简体   繁体   中英

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

any idea how can i update the value using api?

Maybe you could run an update function that get's the value out of the API? What do you use to communicate with the API? You could temporarily store it in the session storage or 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM