D4
=== *
Size: a a a
D4
S
D4
АШ
A
S
D4
IS
async function fetchRecursive(base_url, arr) {
const result = [];
if (Array.isArray(arr))
for (const n of arr) {
if (n.children) {
let ch_arr;
try {
result.push({
id: n.id,
externalId: n.externalId,
text: n.text,
children: await fetch(base_url + n.id).then((r) => {
ch_arr = { ...r };
return r.json();
}),
productCount: n.productCount,
});
} catch (error) {
result.push({ id: n.id, error });
}
result.push(...(await fetchRecursive(base_url, ch_arr)));
} else {
result.push(n);
}
}
return result;
}
{id: 13661, externalId: "КЗ000000000000002853", text: "J-Y (ST) Y", children: false, productCount: 3}
D4
IS
D4
IS
D4
[ {
"id": 1193,
"externalId": "КЗ000000000000002764",
"text": "Изделия для монтажа и опрессовки кабеля",
"children": true,
"productCount": 20025
},
{
"id": 79192,
"externalId": "КЗ000000000000003737",
"text": "Измерительное оборудование",
"children": true,
"productCount": 1559
},
{
"id": 260275,
"externalId": "ШП8-2к00000000231004",
"text": "Инструменты и средства защиты",
"children": true,
"productCount": 21224
},
]
children: true
, то подставляешь в api его id, и то же самое. А заказчик хочет, чтоб я это все деревом отображал, в менюшкеD4
IS
[ {
"id": 1193,
"externalId": "КЗ000000000000002764",
"text": "Изделия для монтажа и опрессовки кабеля",
"children": true,
"productCount": 20025
},
{
"id": 79192,
"externalId": "КЗ000000000000003737",
"text": "Измерительное оборудование",
"children": true,
"productCount": 1559
},
{
"id": 260275,
"externalId": "ШП8-2к00000000231004",
"text": "Инструменты и средства защиты",
"children": true,
"productCount": 21224
},
]
children: true
, то подставляешь в api его id, и то же самое. А заказчик хочет, чтоб я это все деревом отображал, в менюшкеD4
IS
D4
IS
D4