科室显示id

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 ''
    }
}
posted @ 2024-04-03 10:10  hello芳芳  阅读(1)  评论(0编辑  收藏  举报