json树形数据根据子级id查找得到父级id集合

2020-10-16  本文已影响0人  INGME
getParents(data, id) {       // 根据value值匹配
      for (const i in data) {
        if (data[i].value === id) {
          return [data[i].value]
        }
        if (data[i].children) {
          const result = this.getParents(data[i].children, id)
          if (result !== undefined) {
            return result .concat(data[i].value)
          }
        }
      }
    }
上一篇 下一篇

猜你喜欢

热点阅读