var strArr = [];
var node = [{ id: '2011' }, { id: '1231' }, { id: '23' }];
var str = "201133";
var lastStr = "";
//将当前节点切割找出所属父节点Id
if (str.length > 2) {
for (let i = 0; i < str.length - 2; i += 2) {
lastStr += str.slice(i, i + 2);
strArr.push(lastStr);
}
} else {
strArr.push(str);
}
console.log("nodes:" + node);
console.log("currNode:" + strArr);
//循环当前节点并在全局数据查找其父节点是否存在
for (let i = 0; i < strArr.length; i++) {
let tempId = node.find(({ id }) => id === strArr[i])
if (tempId != undefined) { //
console.log("节点存在:" + tempId.id)
} else {
console.log("无父节点:" + strArr[i])
}
}
console