element中的樹形組件,如何獲取父級菜單的id


一般多選的樹形組件,使用getCheckedNodes()方法只能獲取到本級的菜單id,只有在子菜單全部選中的情況下才會選中上級。但我們想要不全選中子級的情況下也要獲取它的上級,甚至上上級等,怎么辦呢?

需要改一下node_modules中的源碼:文件路徑為node_modules\element-ui\lib\element-ui.comment.js

搜索文中的TreeStore.prototype.getCheckedNodes方法,改為:

if ((child.checked || child.indeterminate) && (!leafOnly || leafOnly && child.isLeaf)) {
    checkedNodes.push(child.data)
}

 就ok啦!

在代碼里仍然是this.$refs.tree.getCheckedNodes(),這樣使用。

 


免責聲明!

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



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