[英]How can i update value using api call?
increment(sku){
for (let index = 0; index < this.foods.length; index++){
if (this.foods[index].food.sku == sku)
{
var food_quantity = this.foods[index].quantity++;
var id= this.foods[index].variation.id;
YH.api('cart', 'POST', null, function(data) {
console.log("ID and Quantity", id, food_quantity);
if(data.variation_id == id)
{
data.quantity = food_quantity;
console.log('test');
}
});
}
}
},
This is my increment method when i click on increment button the values changes but when i refresh the page the old value still remain.这是我的增量方法,当我单击增量按钮时,值会发生变化,但是当我刷新页面时,旧值仍然存在。 this is my api
这是我的 api
any idea how can i update the value using api?知道如何使用 api 更新值吗?
Maybe you could run an update function that get's the value out of the API?也许您可以运行更新 function 以获取 API 的值? What do you use to communicate with the API?
您使用什么与 API 进行通信? You could temporarily store it in the session storage or localStorage
您可以将其临时存储在 session 存储或 localStorage
I'm not sure I understand your question properly, but if you want to store your changes, you will need some kind of storage system: basically, you need a database.我不确定我是否正确理解了您的问题,但是如果您想存储更改,则需要某种存储系统:基本上,您需要一个数据库。 This way, you'll save changes applied to your variables so the next time you make an API call, you will update the values that you stored in your database during the previous API call.
这样,您将保存应用于变量的更改,以便下次进行 API 调用时,您将更新在上一次 API 调用期间存储在数据库中的值。
There are different types of databases and many different solutions.有不同类型的数据库和许多不同的解决方案。 If you work with javascript, maybe you want to check MongoDB ( https://www.mongodb.com/ ) to stick with JSON.
If you work with javascript, maybe you want to check MongoDB ( https://www.mongodb.com/ ) to stick with JSON.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.