I need to update my values with recursion but my loop no work? First check code:
const minusItem = (items) => {
console.log("items", items);
if (items.length > 0) {
items.forEach((orgUnit) => {
orgUnit.dashCheck = true;
orgUnit.allChildItemChecked = false;
if (orgUnit.parentNode.unitId) {
minusItem(orgUnit.parentNode); //recursion
}
});
}
};
items is array but worst of all sometimes an object is sent but there is an if that says
items.length > 0
here I filter only strings that have length> 0
array is like
[
{
unitId: 1 ,
title: "Test 1 " ,
dashCheck: false,
allChildItemChecked: false
parentNode: {
unitId: 2 ,
title: "Test 2" ,
dashCheck: false,
allChildItemChecked: false,
parentNode: {
unitId: 3 ,
title: "Test 3" ,
dashCheck: false,
allChildItemChecked: false,
}
}
}
]
of these parentNode can have 100....
I need to loop thought each and set
orgUnit.dashCheck = true;
orgUnit.allChildItemChecked = false;