זה הקוד בצורה מסודרת.
wixData.queryReferenced("hazmanot", id, "muzarim")
.then((results) => {
if (results.items.length > 0) {
let firstItem = results.items;
console.log(firstItem);
mlay(firstItem)
} else {
}
})
.catch((err) => {
let errorMsg = err;
});
export function mlay(firstItem) {
var i;
for (i in firstItem.nimcar) {
var id = firstItem._id
wixData.get("muzarim", id)
.then((item) => {
item.nimcar = Number(item.nimcar - 1)
wixData.update("muzarim", item);
})
.catch((err) => {
let errorMsg = err;
});
}
}
הבעיה היא פה
for (i in firstItem.nimcar)
אתה לא עובר על כל האלמנטים בצורה נכונה.
firstItem מערך ותחפש בגוגל.
https://www.google.com/search?q=foreach+array+js
כלומר מעבר על כל המערך בשפת JS.
בהצלחה.
