实现带有复选框的el-table在进入页面时复选框的状态时选中状态

this.$nextTick(() => {
          **var arr = []
          this.tableData.forEach(item => {
            arr.push(item.id)
          })
          this.addUserAuthorityData.forEach(row => {
            if (arr.indexOf(row.id) != -1) {**
            this.$refs.addUserAuthorityRef.toggleRowSelection(row, true)
          }
})
代码说明:1. 由于是要在table表格渲染完成后,才能进行选中,所以需要使this.$nextTick
		 2. tableData中存储的是需要选中的数据(数组中是对象)
		 3. addUserAuthorityData 是渲染表格需要的数据(tableData中的数据是addUserAuthorityData中的部分或者全部数据,在判断tableData中的每一项是否在addUserAuthorityData中时,使用indexOf()方法是行不通的,由于此处知道tableData中的数据来源于addUserAuthorityData,因此采用了上述带**部分的方法判断是否存在)
		 4. 要使用toggleRowSelection方法,使用这个方法需要获取真实的dom,因此需要给table表格增加ref属性,addUserAuthorityRef 这个就是table表格的ref

猜你喜欢

转载自blog.csdn.net/wangdong9395/article/details/106265011