for (let i = 0; i < el.treeNodeList.length; i++) {
if (el.treeNodeList[i].id===newChild[0].parentId){
let index = el.treeNodeList[i].treeNodeList.findIndex(d => d.id === newChild[0].id);
el.treeNodeList[i].treeNodeList.splice(index,1,newChild[0]);
}
}
-
if (el.treeNodeList[i].id===newChild[0].parentId){//找到treeNodeList中是否包含需要替换的元素
- findIndex找到需要替换的元素的下标
- splice替换掉旧元素
- 注:此思路仅供参考,记录一下