[update 首页] 翻译
This commit is contained in:
@@ -738,3 +738,26 @@ export function queryStandardInfoByStandardNumber (standardNumber) {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找树节点
|
||||
* @param tree {Array} - 树结构
|
||||
* @param findVal - 查找的值
|
||||
* @param valueField - 查找的属性名
|
||||
* @param childrenField - 子节点属性名
|
||||
* @return {null | Object} - 返回对应节点
|
||||
*/
|
||||
export function findNodeByField (tree, findVal, valueField = 'id', childrenField = 'children') {
|
||||
for (const node of tree) {
|
||||
if (node[valueField] === findVal) {
|
||||
return node
|
||||
}
|
||||
if (node[childrenField] && node[childrenField].length > 0) {
|
||||
const result = findNodeByField(node[childrenField], findVal)
|
||||
if (result) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user