first
This commit is contained in:
38
commons/utils/dataKit.js
Normal file
38
commons/utils/dataKit.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* 数据 工具类
|
||||
*
|
||||
* @author terrfly
|
||||
* @site https://www.jeepay.vip
|
||||
* @date 2022/11/30 14:18
|
||||
*/
|
||||
|
||||
const model = {
|
||||
|
||||
// 递归遍历树状结构数据 matchFunc 匹配结果, true表示匹配成功, 否则继续匹配。
|
||||
// pnode 可不传入
|
||||
// 返回结构: [当前数据, 上级数据 ]
|
||||
recursionTreeData: (treeData, matchFunc, childrenName = 'children', pnode = null ) => {
|
||||
|
||||
for (let i = 0; i < treeData.length; i++) {
|
||||
|
||||
const item = treeData[i]
|
||||
|
||||
// 匹配成功
|
||||
if(matchFunc(item)){
|
||||
return [item, pnode]
|
||||
}
|
||||
|
||||
if (item[childrenName] && item[childrenName].length > 0) {
|
||||
let res = model.recursionTreeData(item[childrenName], matchFunc, childrenName, item)
|
||||
if(res){
|
||||
return res
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default model
|
||||
|
||||
Reference in New Issue
Block a user