|
@@ -66,24 +66,22 @@ export default {
|
|
|
return tree;
|
|
|
},
|
|
|
listToTree(list) {
|
|
|
- var map = {},
|
|
|
- node,
|
|
|
- tree = [],
|
|
|
- i;
|
|
|
- for (i = 0; i < list.length; i++) {
|
|
|
- map[list[i].id] = list[i];
|
|
|
- list[i].children = [];
|
|
|
- }
|
|
|
- for (i = 0; i < list.length; i += 1) {
|
|
|
- node = list[i];
|
|
|
- if (node.parentCode) {
|
|
|
- // map[node.parentCode].children = [];
|
|
|
- map[node.parentCode].children.push(node);
|
|
|
+ let map = {};
|
|
|
+ let result = [];
|
|
|
+ // 存映射,方便取值
|
|
|
+ list.forEach((el) => {
|
|
|
+ map[el.id] = el;
|
|
|
+ });
|
|
|
+ list.forEach((item) => {
|
|
|
+ const father = map[item.parentCode];
|
|
|
+ if (father) {
|
|
|
+ (father.children || (father.children = [])).push(item);
|
|
|
} else {
|
|
|
- tree.push(node);
|
|
|
+ result.push(item);
|
|
|
}
|
|
|
- }
|
|
|
- return tree;
|
|
|
+ });
|
|
|
+
|
|
|
+ return result;
|
|
|
},
|
|
|
},
|
|
|
watch: {
|