鍍金池/ 問答/HTML/ iview tree組件如何能選中文字的時(shí)候展開當(dāng)前列

iview tree組件如何能選中文字的時(shí)候展開當(dāng)前列

clipboard.png

回答
編輯回答
凝雅

:on-select-change 點(diǎn)擊樹節(jié)點(diǎn)時(shí)觸發(fā) 當(dāng)前已選中的節(jié)點(diǎn)數(shù)組

on-select-change="handleSelect"

methods:{
    handleSelect(selectedList){
        var ele = selectedList[selectedList.length-1] //當(dāng)前選中的樹節(jié)點(diǎn)
        ele.expand = true //設(shè)置為展開
    }
}
2018年5月23日 00:44
編輯回答
遺莣

你觸發(fā)他on-check-change 也就是復(fù)選框事件的時(shí)候 觸發(fā)他的展開當(dāng)先選中事件啊

2018年8月3日 07:33
編輯回答
鹿惑
<Tree ref="tree" :data="data" :load-data="loadData" @on-select-change="selectChange" show-checkbox/>
methods:{
  selectChange (selectedList) {
      // 獲取當(dāng)前節(jié)點(diǎn)
      const node = selectedList[selectedList.length - 1]
      if (node) {
        // 遞歸(后端邏輯是傳父節(jié)點(diǎn)id,返回子節(jié)點(diǎn)列表)
        this._loadData(node.id, (response) => {
          // 沒有子節(jié)點(diǎn)則返回
          if (!response) return
          let array = []
          // 遍歷子節(jié)點(diǎn),然后在各子節(jié)點(diǎn)上遞歸調(diào)用_loadData查詢孫子、曾孫子...
          response.forEach((item) => {
            array.push(item)
            this._loadData(item.id, () => {})
          })
          // 掛載子節(jié)點(diǎn)
          node.children = array
          // 展開子節(jié)點(diǎn)樹
          node.expand = true
        })
      }
    }
},
mounted () {
    this._loadData(this.id, (array) => {
        this.data = array
    })
}
2018年6月1日 10:48