linkmore-design
Version:
π πlmη»δ»ΆεΊγπ
40 lines (39 loc) β’ 842 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.treeFind = exports.default = void 0;
/**
* ζ₯ζΎεζζ θηΉ
* @param tree
* @param func
* @param options
* @returns
*/
const treeFind = (tree, func, options = {}) => {
const {
children = 'children'
} = options;
let list = [];
if (Array.isArray(tree)) {
list = tree;
} else if (Object.prototype.toString.call(tree) === '[object Object]') {
list.push(tree);
}
for (let i = 0; i < list.length; i += 1) {
const data = list[i];
if (func(data)) {
return data;
}
if (data[`${children}`]) {
const res = treeFind(data[`${children}`], func, options);
if (res) {
return res;
}
}
}
return null;
};
exports.treeFind = treeFind;
var _default = {};
exports.default = _default;