arr.
forEach
(
element
=>
{
if
(element.
parent_catalog_id
==
'0'
) {
fatherList.
push
(element);
fatherId.
push
(element.
id
);
}
else
{
childList.
push
(element);
childParentList.
push
(
parseInt
(element.
parent_catalog_id
));
let
drr =
this
.
traversalTree
(fatherId, fatherList, childList, childParentList);
traversalTree
(
fatherId, fatherList, childList, childParentList
) {
let
subFatherList = [];
let
subFatherId = [];
let
subChildList = [];
let
subChildParentList = [];
childParentList.
forEach
(
(
item, index
) =>
{
const
num = fatherId.
indexOf
(item);
if
(num > -
1
) {
if
(!(fatherList[num].
children
&& fatherList[num].
children
.
length
>
0
)) {
fatherList[num].
children
= [];
fatherList[num].
children
.
push
(childList[index]);
subFatherList.
push
(childList[index]);
subFatherId.
push
(childList[index].
id
);
}
else
{
subChildList.
push
(childList[index]);
subChildParentList.
push
(
parseInt
(childList[index].
parent_catalog_id
));
if
(subChildList.
length
>
0
) {
let
resultChildArr =
this
.
traversalTree
(subFatherId, subFatherList, subChildList, subChildParentList);
resultChildArr.
forEach
(
(
item, index
) =>
{
const
num = fatherId.
indexOf
(
parseInt
(item.
parent_catalog_id
));
fatherList[num].
children
.
some
(
(
element, inx
) =>
{
if
(item.
id
== element.
id
) {
fatherList[num].
children
[inx] = item;
return
true
;
return
fatherList;
复制代码