UNPKG

util-helpers

Version:

一个基于业务场景的工具方法库

36 lines (32 loc) 1.12 kB
'use strict'; var ut2 = require('ut2'); function internalFindTreeSelect(tree, predicate, childrenField, path) { if (path === void 0) { path = []; } var result = []; if (ut2.isArray(tree)) { ut2.forEach(tree, function (item) { path.push(item); if (predicate(item)) { result = path; return false; } if (ut2.isObject(item)) { var childs = item[childrenField]; if (ut2.isArray(childs) && childs.length > 0) { var findChildren = internalFindTreeSelect(childs, predicate, childrenField, path); if (findChildren.length > 0) { result = findChildren; return false; } } } path.pop(); }); } return result; } function findTreeSelect(tree, predicate, childrenField) { if (childrenField === void 0) { childrenField = 'children'; } return internalFindTreeSelect(tree, predicate, childrenField); } module.exports = findTreeSelect;