element table 多选框、单选框如何反显数据?

图片描述

补充:

  1. 第一次创建选择来了部分配件(左侧多选框),修改的时候,先动态查询配件列表,再将选择的那些给反显上去。 如下,无效

    watch: {

        dialogTableVisible(val){  
            if(val){ //弹框 弹出时 反显已选中
              this.$nextTick(()=>{
                  this.productListData1.forEach((item,index)=>{//选中数据
                          this.productListData.forEach((listItem,listIndex)=>{ //配件列表所有数据
                                  if(item.id == listItem.id){   
                                    this.$refs.productListTable.toggleRowSelection(listItem);
                                    }
                           })
                    })
              })
         }
       }
      }
     
    1. 表格单选

我是修改别人的代码,如下实现的单选。
暂时只在处理多选,但是单选我看了一下,表格中每一行都用的这个v-model="radioNum",同一个变量。。没见过这种用法。。。

 
<el-table-column label="是否默认配件" prop="isDefault" width="130" align='center'>
                <template slot-scope="scope">
                    <div v-if="scope.row">
                        <el-radio v-model="radioNum" :label="scope.$index"  @change.native="radioChange(scope)" >&nbsp;</el-radio>
                    </div>
                </template>
            </el-table-column>
阅读 10.3k
2 个回答

更新 2019年3月22日08:18:17

<el-radio v-model="radioNum" :label="scope.$index" @change.native="radioChange(scope)" >&nbsp;</el-radio>

其实重点就是 v-model:label
分析一下就是点一下 v-model 会变成 $index。所有咯,取值用 index 取。回显就给 v-model 赋值对应的下标咯


反显?反选?
http://element-cn.eleme.io/#/...

<el-button @click="toggleSelection([tableData3[1], tableData3[2]])">切换第二、第三行的选中状态</el-button>
 toggleSelection(rows) {
    if (rows) {
      rows.forEach(row => {
        this.$refs.multipleTable.toggleRowSelection(row);
      });
    } else {
      this.$refs.multipleTable.clearSelection();
    }
  },

v-model 上有值,就会回显,这是双向的,类似 input 的 v-model 。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题