|
@@ -1,7 +1,7 @@
|
|
|
/*
|
|
|
* @Author: your name
|
|
|
* @Date: 2021-12-13 09:43:22
|
|
|
- * @LastEditTime: 2022-03-16 16:51:25
|
|
|
+ * @LastEditTime: 2022-03-17 09:41:18
|
|
|
* @LastEditors: your name
|
|
|
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
|
* @FilePath: \Foshan4A2.0\src\utils\validate.js
|
|
@@ -45,16 +45,27 @@ export function translateDataToTreeAll(data, parentKey, parentIDKey) {
|
|
|
let translator = (parent, children) => {
|
|
|
parent.forEach((parent) => {
|
|
|
parent.children = [];
|
|
|
- children.forEach((current, index) => {
|
|
|
- if (current[parentKey] === parent[parentIDKey]) {
|
|
|
- const temp = JSON.parse(JSON.stringify(children));
|
|
|
- temp.splice(index, 1);
|
|
|
- translator([current], temp);
|
|
|
- typeof parent.children !== "undefined"
|
|
|
- ? parent.children.push(current)
|
|
|
- : (parent.children = [current]);
|
|
|
+ // children.forEach((current, index) => {
|
|
|
+ // if (current[parentKey] === parent[parentIDKey]) {
|
|
|
+ // const temp = JSON.parse(JSON.stringify(children));
|
|
|
+ // temp.splice(index, 1);
|
|
|
+ // translator([current], temp);
|
|
|
+ // typeof parent.children !== "undefined"
|
|
|
+ // ? parent.children.push(current)
|
|
|
+ // : (parent.children = [current]);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ for (let i = 0; i < children.length;) {
|
|
|
+ if (children[i][parentKey] === parent[parentIDKey]) {
|
|
|
+ const temp = children.splice(i, 1)
|
|
|
+ typeof parent.children !== 'undefined'
|
|
|
+ ? parent.children.push(...temp)
|
|
|
+ : (parent.children = temp)
|
|
|
+ translator(temp, children)
|
|
|
+ } else {
|
|
|
+ i++
|
|
|
}
|
|
|
- });
|
|
|
+ }
|
|
|
});
|
|
|
};
|
|
|
translator(parent, children);
|