【发布时间】:2021-03-23 12:46:16
【问题描述】:
我有一个包含如下对象的数组:
tree = [
{
id: 1,
name: "parent1",
children: [
{
id: 2,
name: "child1",
children: [
{ id: 4, name: "subChild1",dateType:"hijri" },
{ id: 5, name: "subChild2",dateType:"hijri" }
]
},
{ id: 3, name: "child2" }
]
}
];
还有另一个数组,例如:
result= [{id:4,dateType:"Geo"},{id:5,dateType:"another"}]
我想遍历第二个数组,并且对于第一个数组中的每个节点都满足条件 id=id ,我需要更改它的 dateType 值,如下所示:
this.result.forEach(res => {
this.flattenItems(this.tree).find(
item => item.id == res.id
).itemType =res.dateType;
});
注意这棵树来自 3 层,并且只在最后一层进行操作
有没有办法使用lodash实现循环?
【问题讨论】:
标签: javascript collections treeview lodash