el-tree中的checkbox狀態添加disabled屬性


在elementUI的組件中,沒有對el-tree里面的復選框設置不可修改狀態;只能在每個對象里面添加disabled屬性,才能達到想要的結果。

如下圖:

 

 

 所以當我們想禁用所有狀態的時候,就可以使用迭代的方式滿足需求,具體如下代碼:

created() {
    this.getLoadData()
  },
methods:{   setDisabled(arr) {
for (var i = 0; i < arr.length; i++) { arr[i]['disabled'] = this.disabled if (arr[i].children && arr[i].children.length > 0) { this.setDisabled(arr[i].children) } } },   getLoadData(node, callback) { var orgList = [{ id: 1, label: '一級 2', children: [{ id: 3, label: '二級 2-1', children: [{ id: 4, label: '三級 3-1-1' }, { id: 5, label: '三級 3-1-2', }] }, { id: 2, label: '二級 2-2', disabled: true, children: [{ id: 6, label: '三級 3-2-1' }, { id: 7, label: '三級 3-2-2', }] }] }] this.data = orgList this.setDisabled(this.data) }) }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM