elementUI 表格中回显checkbox是否选中

摘要:
我是通过v-if指令来做的,我用的是checked3,checked4在data质指定。官方文档不太明白这个是什么情况,直接指定不行,为什么,分页的时候第二页就有问题了后面发现上面的还是有问题,点第二页的时候,如果第一页默认选中了1,,2条,第二页也会同样1,2条被选中,尽管按照状态来说不改该呗选中。

我是通过v-if指令来做的,我用的是

checked3,checked4在data质指定。
 <el-table :data="devicesGridData">
              <el-table-column property="name" label="选择" width="80">
             
                <template slot-scope="scope">
                  <div v-if="1==scope.row.isSelected">
                    <el-checkbox v-model="checked3"  @change="deviceBoxChange(scope.row.id)"></el-checkbox>
                  </div>
                  <div v-if="0==scope.row.isSelected">
                    <el-checkbox v-model="checked4"   @change="deviceBoxChange(scope.row.id)"></el-checkbox>
                  </div>
                </template>
              </el-table-column>
              <el-table-column property="code" label="设备编号" width="100"></el-table-column>
              <el-table-column property="name" label="设备名称" width="100"></el-table-column>
              <el-table-column property="modelType" label="设备规格"></el-table-column>
          </el-table>

下面是错误的方法!!!!!!!!!!!!

官方文档

elementUI 表格中回显checkbox是否选中第1张

不太明白这个是什么情况,直接指定不行,为什么,分页的时候第二页就有问题了

 <el-table :data="devicesGridData">
              <el-table-column property="name" label="选择" width="80">
             
                <template slot-scope="scope">
                  <div v-if="1==scope.row.isSelected">
                    <el-checkbox checked="true"  @change="deviceBoxChange(scope.row.id)"></el-checkbox>
                  </div>
                  <div v-if="0==scope.row.isSelected">
                    <el-checkbox checked="false"   @change="deviceBoxChange(scope.row.id)"></el-checkbox>
                  </div>
                </template>
              </el-table-column>
              <el-table-column property="code" label="设备编号" width="100"></el-table-column>
              <el-table-column property="name" label="设备名称" width="100"></el-table-column>
              <el-table-column property="modelType" label="设备规格"></el-table-column>
          </el-table>

后面发现上面的还是有问题,点第二页的时候,如果第一页默认选中了1,,2条,第二页也会同样1,2条被选中,尽管按照状态来说不改该呗选中。

<el-table :data="devicesGridData" ref="multipleTable"  @selection-change="handleSelectionChange">>
               <el-table-column type="selection" width="55">
               </el-table-column>
              <el-table-column property="code" label="设备编号" width="100"></el-table-column>
              <el-table-column property="name" label="设备名称" width="100"></el-table-column>
              <el-table-column property="modelType" label="设备规格"></el-table-column>
          </el-table>
注意上下分别对应:devicesGridData,multipleTable
套了层壳:
this.$nextTick(function () {//选中逻辑代码},主要是解决数据加载前后问题导致分页的时候,数据无法回显复选框。
this.$nextTick(function () {
              this.devicesGridData.forEach(row=>{
                      if(row.selected){
                        this.$refs.multipleTable.toggleRowSelection(row,true);
                      }
                    }); 
          });

免责声明:文章转载自《elementUI 表格中回显checkbox是否选中》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇HTML5的Video标签的属性,方法和事件汇总Jmeter之设置线程组运行次数/时间下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

oracle--pl/sql变量定义----

一、变量介绍 在编写pl/sql程序时,可以定义变量和常量;在pl/sql程序中包括有: 1)、标量类型(scalar) 2)、复合类型(composite) --用于操作单条记录 3)、参照类型(reference) --用于操作多条记录 4)、lob(large object) 二、标量(scalar)——常用类型 1)、在编写pl/sql块时,如果...

Mysql中查询索引和创建索引

查询索引   show index from table_name 1.添加PRIMARY KEY(主键索引) ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` ) 2.添加UNIQUE(唯一索引) ALTER TABLE `table_name` ADD UNIQUE ( `column` ) 3.添...

jQuery .tmpl(), .template()学习资料小结

昨晚无意中发现一个有趣的jQuery插件.tmpl(),其文档在这里。官方解释对该插件的说明:将匹配的第一个元素作为模板,render指定的数据,签名如下: .tmpl([data,][options]) 其中参数data的用途很明显:用于render的数据,可以是任意js类型,包括数组和对象。options一般情况下都是选项了,官方指出,此处的optio...

mysql alter 语句用法,添加、修改、删除字段等

//主键549830479 alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id); //增加一个新列549830479 alter table t2 add...

Python之pandas读取mysql中文乱码问题

# -*- coding: utf-8 -*- # author:baoshan import pandas as pd import pymysql config = { "host": "localhost", "port": 3306, "user": "root", "password": "12...

oracle pl/sql 变量

一、变量介绍在编写pl/sql程序时,可以定义变量和常量;在pl/sql程序中包括有:1)、标量类型(scalar)2)、复合类型(composite) --用于操作单条记录3)、参照类型(reference) --用于操作多条记录4)、lob(large object)    二、标量(scalar)——常用类型1)、在编写pl/sql块时,如果要使用...