const data = {
group: "Group1",
attributes: { name: "Item1" },
children: [
{ attributes: { name: "SubItem1" } },
{ attributes: { name: "SubItem2" } },
{
group: "Group2",
attributes: { name: "Item2" },
children: [{ attributes: { name: "SubItem3" } }, { attributes: { name: "SubItem4" } }],
},
],
};
结果
{
Group1: [Item1,SubItem1,SubItem2, Item2,SubItem3,SubItem4],
Group2: [Item2,SubItem3,SubItem4]
}
数组中的顺序并不重要。
我会建议这个选项...