returnParents(list, id) {
//返回父级id数组
let that = this;
let act = new Array();
list.forEach(item => {
if (item.id == id) {
act.unshift(item.id);
return act;
}
if (item.children && item.children.length > 0) {
var obj = that.returnParents(item.children, id);
if (obj && obj.length > 0) {
obj.unshift(item.id);
act = obj;
}
}
});
return act;
},
returnItself(list, id) {
// 只返回id所在当前元素
let that = this;
let act = new Array();
list.forEach(item => {
if (item.id == id) {
act.push(item);
return act;
}
if (item.children && item.children.length > 0) {
var obj = that.returnItself(item.children, id);
if (obj && obj.length > 0) {
act = obj;
}
}
});
return act;
},