Home > front end >  For bosses, take a look at this code can be written as recursive, the couple don't know how to
For bosses, take a look at this code can be written as recursive, the couple don't know how to

Time:03-31

 enclosing dataList. ForEach (item=& gt; {
If (item. Children==null) {
Enclosing checkedKeys. Push (item. BudgetItemId)
} else {
Item. Children. ForEach (ite=& gt; {
If (ite. Children==null) {
Enclosing checkedKeys. Push (ite. BudgetItemId)
} else {
Ite. Children. ForEach (it=& gt; {
If (it. The children==null) {
This. CheckedKeys. Push (it. BudgetItemId)
} else {
It. The children. The forEach (it2=& gt; {
Enclosing checkedKeys. Push (it2. BudgetItemId)
})
}
})
}
})
}
})

For bosses to see, how should this code written in recursive ah

CodePudding user response:

Himself wrote a function, into two, one is the source data (this) datalist/item) children), another is the enclosing checkedKey, if the enclosing checkedKey is a global variable, that may not be defined as the reference, you just need to a source data parameter
 
The function fn (data) {
Data. The forEach (item=& gt; {
Item. The children? Fn (item. Children) : this. CheckedKeys. Push (item. BudgetItemId);
})
}
Fn (enclosing datalist)

CodePudding user response:

UnforlAll (data) {
Data. The forEach ((el)=& gt; {
El. Children & amp; & El. Children==null
? Enclosing unforlAll (el. Children)
: this. CheckedKeys. Push (el) budgetItemId);//child level recursive
});
},
  • Related