function transformTreeData (flatArrs, parentItem) {
var children = flatArrs.filter((item, index) => {
return item.parentId == parentItem.id;
}).map(record => {
record.label = record.name
record.value = record.id
record.key = record.id
return record
});
parentItem.children = children;
for (var i in children) {
this.transformTreeData(flatArrs, children[i]);
}
return parentItem.children
},
transformTreeData(array, {id: 0})
array数组格式:
[{
id: 1, parentId: 0
}]