// 查找树中某一个符合条件的子节点
/**
*
* @param {array} tree //传入的树节点
* @param {string|number} key
* @param {object} options
* @returns {array} 返回查找到的节点
*/
export const treeFind = function (
tree,
key,
{ nodeKey = 'id', childrenKey = 'children' } = {},
recursiveParams = { isFind: false, result: null }
) {
console.log(tree, 'tree')
tree.some(v => {
if (recursiveParams.isFind) return true
const isSame = v[nodeKey] === key
if (isSame) {
recursiveParams.isFind = isSame
recursiveParams.result = v
return isSame
}
if (v[childrenKey] && v[childrenKey].length) {
treeFind(v[childrenKey], key, { key, childrenKey }, recursiveParams)
}
})
return recursiveParams.result
}
// 调用方法
treeFind(this.tableData, row.parentId)