My API returns JSON data in the following format:
{'items':[
{'id': 1, 'quantity': 3},
{'id': 4, 'quantity': 7},
{'id': 5, 'quantity': 1}
]}
I have configured my page to fetch this API every 15 seconds. However, I have encountered a problem where the order of items in the array changes each time the API is called. This results in the blocks on my page changing their order as well. I attempted to address this issue by:
for (var i in response.items) {
let current_item = response.items[i];
for (var i2 in original_items.items) {
if (original_items.items[i2].id === current_item.id) {
original_items.items[i2] = current_item;
}
}
}
Unfortunately, this solution did not work as expected. Sorting the items by ID also proved to be ineffective. Any suggestions on how to tackle this issue?