hasDepartmentIdFn(treeData, key) { this.hasDepartmentId = false const loop = (data) => { for (const item of data) { if (item.treedataid === key) { this.hasDepartmentId = true break } if (item.childList && item.childList.length) { loop(item.childList) } } } loop(treeData) }, this.hasDepartmentIdFn(res.data, this.mainForm.lngdepartmentid) if (this.hasDepartmentId) { ... } 其他 export function getNodeByPropertyAndValue(treeData, key, value, compare) { if (!treeData || !treeData.length) return null if (!compare) compare = (a, b, item) => a === b let node = null const loop = (data) => { for (const item of data) { if (compare(item[key], value, item)) { node = { ...item } break } if (item.childList && item.childList.length) { loop(item.childList) } } } loop(treeData) return node } methods: { getNodeByPropertyAndValue, getDictionaryName(datalist, value) { const node = this.getNodeByPropertyAndValue(datalist, 'treedataid', value) if (node) { return node.treedatacodeandname } return '' } }
标签:node,显示,treeData,childList,item,科室,data,id,loop From: https://www.cnblogs.com/hellofangfang/p/18112072