You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
simple-yewu/frontend/web/js/tree/js/handledata.js

30 lines
546 B

function getLevelById(data,id) {
return getParents(data,id).length;
}
function hasChilds(data,id){
return getChildById(data,id).length !== 0;
}
function getChildById(arr,pid){
var newArr = [];
for( var i = 0; i < arr.length; i++ ){
if( arr[i].pid == pid ){
newArr.push(arr[i]);
}
};
return newArr;
}
function getParents(data,currentId){
var arr = [];
for( var i = 0; i < data.length; i++ ){
if( data[i].id == currentId ){
arr.push(data[i]);
arr = arr.concat(getParents(data,data[i].pid))
break;
}
}
return arr;
}