el-table的toggleRowSelection方法不生效是什么原因

我需要做一个在打开弹窗的时候已经选择过的数据在表格里勾中,使用了toggleRowSelection方法,但是么有用,不知道为什么
表格的代码:

<el-table ref="multipleTable" :data="courseList" max-height="288" row-key="id" @selection-change="handleSelectionChange">
  <el-table-column type="selection" align="center" :reserve-selection="true" />
</el-table>
<pagination
  :total="courseTotal"
  :page.sync="courseQuery.pageIndex"
  :page-sizes="[5, 10, 15, 20]"
  :limit.sync="courseQuery.pageSize"
  @pagination="getCourseData"
/>

请求数据和调用toggleRowSelection的代码:

initCourseSeletion() {
      this.$nextTick(() => {
        this.courseList.forEach(course => {
          this.detailInfo.courseInfoVoList.forEach(item => {
            if (course.type === item.type && course.id === item.id) {
              this.$nextTick(() => {
                this.$refs.courseTable.toggleRowSelection(course)
              })
            }
          })
        })
      })
    },
getLiveList() {
      getCourseList({ ...this.courseQuery }).then(({ data }) => {
        this.courseList = data.list.map(item => {
          item.type = 1
          return item
        })
        this.initCourseSeletion()
        this.courseTotal = data.total
      })
    },
getCourseList() {
      coursePage({ ...this.courseQuery }).then(({ data }) => {
        this.courseList = data.list.map(item => {
          item.type = 3
          return item
        })
        this.initCourseSeletion()
        this.courseTotal = data.total
      })
    },
// this.courseQuery.commodityType是一个筛选项,根据它的值请求的接口不同
getCourseData() {
      switch (this.courseQuery.commodityType) {
        case 1:
          this.getLiveList()
          break
        case 2:
          this.getCourseList()
      }
    },
阅读 3.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题