|
|
@@ -374,32 +374,33 @@ const pmTree = {
|
|
|
|
|
|
};
|
|
|
|
|
|
- Tree.prototype.check = function (roots, _root) {
|
|
|
- return isValid(roots);
|
|
|
+ Tree.prototype.check = function (_root) {
|
|
|
+ return isValid(_root.children);
|
|
|
function isValid(nodes) {
|
|
|
for (let node of nodes) {
|
|
|
if (node.data.ParentID !== -1 &&
|
|
|
(!node.parent || node.parent.data.ID !== node.data.ParentID)) {
|
|
|
- console.log(node);
|
|
|
- console.log(`node.data.ParentID !== -1 &&
|
|
|
- (!node.parent || node.parent.data.ID !== node.data.ParentID)`);
|
|
|
+ console.log(`${node.serialNo() + 1}:${node.data.name} parent对应错误`);
|
|
|
return false;
|
|
|
}
|
|
|
if (node.data.ParentID === -1 && node.parent && node.parent !== _root) {
|
|
|
- console.log(node);
|
|
|
- console.log(`node.data.ParentID === -1 && node.parent && node.parent !== roots`);
|
|
|
+ console.log(`${node.serialNo() + 1}:${node.data.name} 不应有parent`);
|
|
|
return false;
|
|
|
}
|
|
|
if (node.data.NextSiblingID !== -1 &&
|
|
|
(!node.nextSibling || node.nextSibling.data.ID !== node.data.NextSiblingID)) {
|
|
|
- console.log(node);
|
|
|
- console.log(`node.data.NextSiblingID !== -1 &&
|
|
|
- (!node.nextSibling || node.nextSibling.data.ID !== node.data.NextSiblingID)`);
|
|
|
+ console.log(`${node.serialNo() + 1}:${node.data.name} next对应错误`);
|
|
|
return false;
|
|
|
}
|
|
|
if (node.data.NextSiblingID === -1 && node.nextSibling) {
|
|
|
- console.log(node);
|
|
|
- console.log(`node.data.NextSiblingID === -1 && node.nextSibling`);
|
|
|
+ console.log(`${node.serialNo() + 1}:${node.data.name} 不应有next`);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ let parent = node.parent,
|
|
|
+ nodeIdx = parent.children.indexOf(node),
|
|
|
+ nextIdx = parent.children.indexOf(node.nextSibling);
|
|
|
+ if (nodeIdx !== -1 && nextIdx !== -1 && nodeIdx > nextIdx) {
|
|
|
+ console.log(`${node.serialNo() + 1}:${node.data.name} node索引大于next索引`);
|
|
|
return false;
|
|
|
}
|
|
|
if (node.children.length) {
|