【vue+element table 全选和取消全选】

  
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
        
    

    selectionChange(val) {
      this.multipleSelection = val
      console.log(this.multipleSelection)
    },
    select(selection) {
      this.multipleSelection = selection
      console.log(this.multipleSelection)
    },
    selectAll(selection) {
      const isSelect = selection.some((el) => {
        const tableDataIds = this.InpExamList.map((j) => j.ids)
        return tableDataIds.includes(el.ids)
      })
      // tableDate第一层只要有不在selection里面就是全不选
      const isCancel = !this.InpExamList.every((el) => {
        const selectIds = selection.map((j) => j.ids)
        return selectIds.includes(el.ids)
      })
      if (isSelect) {
        selection.map((el) => {
          if (el.list) {
            el.list.map((j) => {
              this.toggleSelection(j, true)
            })
          }
        })
      }
      if (isCancel) {
        this.InpExamList.map((el) => {
          if (el.list) {
            el.list.map((j) => {
              this.toggleSelection(j, false)
            })
          }
        })
      }
    },

    toggleSelection(row, select) {
      if (row) {
        this.$nextTick(() => {
          this.$refs.multipleTable && this.$refs.multipleTable.toggleRowSelection(row, select)
        })
      }
    },

你可能感兴趣的:(前端)