【发布时间】:2021-11-19 05:36:07
【问题描述】:
为什么 children.length 会导致 Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'length') 特别是因为 children.length 的值已成功显示在控制台上?
const getParentId = (childId) => {
var queue = [ds]
while(queue.length > 0){
const children = queue[0].children
queue.push(children)
console.log("children.length = "+children.length)
for (let i = 0; i < children.length; i++){
if (children[i].id === childId) {return queue[0].id}
}
queue.shift()
}
}
const addSiblingNodes = async () => {
const child = [...selectedNodes][0]
const childId = child.id
const newNodes = getNewNodes()
await dsDigger.addSiblings(childId, newNodes);
setDS({ ...dsDigger.ds });
console.log("the parent of "+childId +" is "+ getParentId(childId))
};
【问题讨论】:
标签: javascript reactjs