|
|
@@ -4,11 +4,10 @@
|
|
|
const pmTree = {
|
|
|
createNew: function (setting, arrData) {
|
|
|
function sortTreeItems(tree) {
|
|
|
- var addItems = function (items) {
|
|
|
- var i;
|
|
|
- for (i = 0; i < items.length; i++) {
|
|
|
- tree.items.push(items[i]);
|
|
|
- addItems(items[i].children);
|
|
|
+ const addItems = function (items) {
|
|
|
+ for (const item of items) {
|
|
|
+ tree.items.push(item);
|
|
|
+ addItems(item.children);
|
|
|
}
|
|
|
};
|
|
|
tree.items.splice(0, tree.items.length);
|
|
|
@@ -254,6 +253,7 @@ const pmTree = {
|
|
|
};
|
|
|
|
|
|
Tree.prototype.loadData = function (arrData) {
|
|
|
+ this.sourceData = arrData;
|
|
|
let i, that = this;
|
|
|
let nodesIndex = {};
|
|
|
function getPreNode(id){
|
|
|
@@ -380,6 +380,15 @@ const pmTree = {
|
|
|
};
|
|
|
|
|
|
Tree.prototype.check = function (_root) {
|
|
|
+ if (this.sourceData.length !== this.items.length) {
|
|
|
+ const data = this.sourceData.filter(item => {
|
|
|
+ const findData = this.items.find(node => node.data.ID === item.ID);
|
|
|
+ return !findData;
|
|
|
+ });
|
|
|
+ console.log('丢失数据:');
|
|
|
+ console.log(data);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
return isValid(_root.children);
|
|
|
function isValid(nodes) {
|
|
|
for (let node of nodes) {
|
|
|
@@ -408,6 +417,10 @@ const pmTree = {
|
|
|
console.log(`${node.serialNo() + 1}:${node.data.name} node索引大于next索引`);
|
|
|
return false;
|
|
|
}
|
|
|
+ if (node.nextSibling && node.parent !== node.nextSibling.parent) {
|
|
|
+ console.log(`${node.serialNo() + 1}:${node.data.name} 与兄弟节点 ${node.nextSibling.serialNo() + 1}:${node.nextSibling.data.name} 父节点不同`);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
if (node.children.length) {
|
|
|
let v = isValid(node.children);
|
|
|
if (!v) {
|