修改Tree数据下的参数(需children)
export const initChildren = function(list,listCreateKey) {
list.forEach(element => {
listCreateKey.forEach(vv=>{
element[vv[0]] = element[vv[1]];
})
if (element.children && element.children.length) {
initChildren(element.children,listCreateKey);
}
});
return list
}
删除Tree数据下的参数
export function initDel(list,listDelKey){
list.forEach((element,index)=>{
let bl =Boolean(false)
listDelKey.forEach(vv=>{
bl = element[vv[0]] != vv[1]
if (bl) {
list.splice(index,1,null)
}
})
if (!bl && element && element.children && element.children.length) {
element.children = initDel(element.children,listDelKey);
}
})
list = list.filter(v=>v)
return list
}
声明:
第一个参数为原始Tree数据,第二个参数为[['新',['原']],['新',['原']]...]