[{
"id": "market-executive-summary",
"title": "Executive Summary",
"interactivity": false,
"priceFactor": 2,
"children": [{
"id": "market-executive-summary-overview",
"title": "Overview",
"interactivity": false,
"priceFactor": 0,
"children": []
}, {
"id": "market-executive-summary-key-findings",
"title": "Key Findings",
"interactivity": false,
"priceFactor": 0,
"children": []
}, {
"id": "market-executive-summary-conclusions-implications",
"title": "Conclusions & Implications",
"interactivity": false,
"priceFactor": 0,
"children": []
}]
},
{
"id": "market-definitions-segmentation",
"title": "Definitions & Segmentation",
"interactivity": false,
"priceFactor": 2,
"children": [{
"id": "market-definitions-segmentation-definitions",
"title": "Definitions",
"interactivity": false,
"priceFactor": 0,
"children": []
}]
}
]
id и isSelected: true | false
const setProp = (arr, data) => {
const {id, isSelected } = data;
}
const setProp = (arr, propData) => {
if (arr.length <= 1) return;
const { id, isSelected } = propData;
arr.forEach((element: any) => {
if (element[id]) {
element[id].isSelected = isSelected;
} else {
setProp(element.children, propData);
}
});
};
const id = "market-executive-summary-key-findings";
const isSelected = true;
const data = {
id, isSelected
}
setProp(arr, data)
const find = (arr, id) =>
(Array.isArray(arr) ? arr : []).reduce((found, n) =>
found ?? (n.id === id ? n : find(n.children, id))
, null);
const obj = find(arr, id);
if (obj) {
obj.isSelected = isSelected;
}