Answer the question
In order to leave comments, you need to log in
How to make values from array-object for attributes dynamic from multiple choices?
1. There is json where all the data is for the basket.
2. There are two objects: var cart = {}; and var cart1 = { 2021: 0, 2022: 0, 2023: 0, 2024: 0 };
3. I extract data:
$.getJSON('goods.json', function (data)
for (var key in data) {
if ((cart) != undefined) {
out1 += '<button class="minus" data-art="' + key + '"">-</button>';
out1 += '<button class="number" data-art="' + key + '">' + cart1[key] + '</button>';
} else {
out1 += '<button class="number" data-art="' + key + '">' + cart[key] + '</button>';
}
out1 += '<button class="plus" data-art="' + key + '">+</button>
}
function plus() {
var articul = $(this).attr('data-art');
if (cart[articul] != undefined) {
cart[articul]++;
}
else {
cart[articul] = 1;
}
localStorage.setItem('cart', JSON.stringify(cart));
loadGoods();
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question