el-table全部展开和全部折叠功能
作者:互联网
1、全部展开(tableData是el-table的填充数据):
expandAll () { let els = document.getElementsByClassName('el-table__expand-icon') if (this.tableData.length !== 0 && els.length !== 0) { for (let j = 0; j < els.length; j++) { els[j].classList.add('dafult') } if (this.$el.getElementsByClassName('el-table__expand-icon--expanded')) { const open = this.$el.getElementsByClassName('el-table__expand-icon--expanded') for (let j = 0; j < open.length; j++) { open[j].classList.remove('dafult') } const dafult = this.$el.getElementsByClassName('dafult') for (let a = 0; a < dafult.length; a++) { dafult[a].click() } } } }
2、全部折叠(tableData是el-table的填充数据):
collapseAll () { if (this.tableData.length !== 0) { const elsopen = this.$el.getElementsByClassName('el-table__expand-icon--expanded') if (this.$el.getElementsByClassName('el-table__expand-icon--expanded')) { for (let i = 0; i < elsopen.length; i++) { elsopen[i].click() } } } }
标签:__,el,getElementsByClassName,length,全部,dafult,table 来源: https://www.cnblogs.com/yiliangmi/p/14328558.html