当前位置:网站首页>toggleRowSelection()失效的2个重要影响因素
toggleRowSelection()失效的2个重要影响因素
2022-06-09 02:21:00 【留白很牛掰】
背景
需求:当我们在含分页器的table做了多选勾选框操作时,分页切换时要保证回显已选中项。
方法
根据文档使用tabled的Method:toggleRowSelection(row, selected)
实际应用
数据请求完直接遍历每个item this.$refs.multipleTable.toggleRowSelection(row,true),这样操作下此函数就会失效。
因素1: ref 文档描述可知
ref 本身是作为渲染结果被创建的,在初始渲染的时候你不能访问它们 - 它们还不存在! $refs 也不是响应式的,因此你不应该试图用它在模板中做数据绑定。
数据更新后Dom会注销新建,导致我们勾选操作失效
因素2: 勾选操作数据必须为所操作的表单数据
我们操作的勾选数据必须是表单数据,即便数据一模一样,数据存储地址的指针不同也会导致失效
解决办法
结合上面所提2条因素
1、使用$nextTick,在dom 更新完成后的回调中来处理渲染选中
2、通过已选数据对比筛选表单数据来操作同一数据
this.checkedData.forEach(item => {
// checkedData为已选数据
this.$nextTick( ()=>{
this.userData.find(obj => {
// userData 表单数据
if(item.id === obj.id) {
this.$refs.multipleTable.toggleRowSelection(obj,true)
}
})
})
})
边栏推荐
- 价值600的抖音云蹦迪直播间项目,靠直播打赏收益的风口项目源码
- 合约私有数据泄漏的安全问题分析及演示
- [SUCTF 2019]EasyWeb
- Cve - 2022 - 30525 Replay of vulnerability
- 数字电路加法器 基本原理(一)
- export相關知識
- Thread synchronization, process synchronization, mutex, semaphore, condition variable, etc
- C # questions about cache and data flow
- Mysql database connection query join principle
- Binary tree chain structure
猜你喜欢

Redis集群搭建
![[1037. effective boomerang]](/img/e2/ccac2e7df2db316da4e88bdc709e6e.png)
[1037. effective boomerang]

Zhihu hot discussion: at the age of 35, do you want to escape Beijing, Shanghai and Guangzhou?

飞书要不要做生态?剖析第一家 All in 飞书的独立 SaaS 案例

二叉树链式结构

Navicat tool batch imports JSON format data to Doris

Don't miss | quota management and application - bank credit card behavior scoring (see for practical operation)

接口测试系列——转转交易业务场景接口测试实践

Integrated base process test summary

Basic architecture of data Lake
随机推荐
From the ECS SSRF vulnerability to taking over your alicloud console
How Bi makes SaaS products have a "sense of security" and "sensitivity" (Part I)
【无标题】
How to use superset to seamlessly connect with MRS for self-service analysis
杰理最后io_key 双按键如何使用?【篇】
[Tianyi cup 2021]esay_ eval
[1037. effective boomerang]
价值600的抖音云蹦迪直播间项目,靠直播打赏收益的风口项目源码
export相关知识
Jerry: if the user doesn't need to use all the keys, how should other keys be set? [chapter]
About the left join, the left join finds more data than the original left table
Basic usage of flask sqlalmy
S series · several postures for deleting folders
27 | discussion on high water level and leader epoch
Buffett's alpha -- part of the code
杰理之关于 SPI 主机配置参数的几个说明篇】
蓝桥杯_青蛙的约会_扩展欧几里得
MySQL data type enum enumeration type
【网络协议】| 【01】网络字节序大端、小端
String 3-387. First unique character in string