Comments (4)
为什么不直接设置 value 的值呢?
from element-plus.
为什么不直接设置 value 的值呢?
因为返回的数据是所有选中的和半选中的id,用value和v-model都无法正确回显值,所以想着用setCheckedKeys方法的第二个参数设置只设置选中的叶子节点状态
另外其实是可以用别的方法解决的,但是发现了这个问题,不知道是bug还是设计如此,所以提了个issue
from element-plus.
为什么不直接设置 value 的值呢?
因为返回的数据是所有选中的和半选中的id,用value和v-model都无法正确回显值,所以想着用setCheckedKeys方法的第二个参数设置只设置选中的叶子节点状态
另外其实是可以用别的方法解决的,但是发现了这个问题,不知道是bug还是设计如此,所以提了个issue
看了下源码,设置绑定值其实就是调用了 setCheckedKeys
。Tree 组件没有像 Input 组件一样把父组件 inject 进来,不过特别地将 Tree 组件的方法都暴露出来了,我也不清楚算不算 bug。不过有选中的id,直接设置应该能满足需求的,可以看看这个Demo
from element-plus.
为什么不直接设置 value 的值呢?
因为返回的数据是所有选中的和半选中的id,用value和v-model都无法正确回显值,所以想着用setCheckedKeys方法的第二个参数设置只设置选中的叶子节点状态
另外其实是可以用别的方法解决的,但是发现了这个问题,不知道是bug还是设计如此,所以提了个issue看了下源码,设置绑定值其实就是调用了
setCheckedKeys
。Tree 组件没有像 Input 组件一样把父组件 inject 进来,不过特别地将 Tree 组件的方法都暴露出来了,我也不清楚算不算 bug。不过有选中的id,直接设置应该能满足需求的,可以看看这个Demo
感谢,我看了这个demo,我补充一下我的应用情况,后端存的时候需要选中的子节点和半选中的父节点的数组,查询的时候自然也是返回了父节点和子节点的id,这样在赋值的时候,直接赋值这个数组,会导致父节点下的所有子节点都被选中,如demo所示,所以想到了用setCheckKeys的第二个参数来保证只有子节点才选中,这样才发现了这个问题的,感觉是在设计的时候没有想到这种情况(这个情况也确实有点极端),但是通过访问实例上的setCheckKeys的时候出现了这个问题,感觉这个组件要么应该适配一下setCheckKeys方法,要么就不暴露这个方法比较好
from element-plus.
Related Issues (20)
- [slider] slider 组件会响应home和end的快捷键,我不想让他响应,我应该怎么做? HOT 11
- [Component] [tree-select] 开启 `allow-create` 时样式错乱
- [Component] [All] Failed to resolve component: el-button If this is a native custom element, make sure to exclude it from component resolution via compilerOptions.isCustomElement. HOT 1
- [Component] [select]: select 配置可清空功能,清空后值变成undefined,类型发生变化 HOT 7
- [Component] [row, col] 当横向渲染分辨率设置为767px时el-col组件布局失去响应式。
- [IDEA] more Types HOT 1
- [Feature Request] More types HOT 5
- [tree-select] el-tree-select
- [Component] [select, select-v2] select中添加了tagTooltip但popper-options属性不能定义导致tagTooltip显示是会被盖住
- [Component] [input] focus事件里面执行blur,会再次出发focus事件 HOT 2
- [Component] [tree] Tree组件 setCheckedKeys接口中leafOnly参数设置无效
- [Component] [tree] 官网上 el-tree 自定义节点类名这个例子好像有问题,叶子节点横向显示有问题 HOT 2
- [Component] [dialog] edge浏览器使用 el-dialog 中嵌套 video 标签,导致video更多选项不显示 HOT 6
- [Component] [button] Button link variant has invalid color HOT 13
- [Component] [tree] 使用tree 拖动元素时候,如果超出了tree的可操作区域就不应该拖动成功,现在可以拖动成功
- [Component] [All] 在谷歌21版本的浏览器中,el-input输入中文自动带入拼音 HOT 3
- [Component] [table-v2] Component] [table-v2] el-table-v2 设置columns的fixed属性后,如果row-key使用数字或者数字开头的字符串,onRowHovered 事件报错
- [Component] [tree-select] TreeSelect 在文档中的分类应当为 Form 表单组件
- [Component] [table, table-column] 当表格中所有列都是fixed时,虽然内容未超出,但表格仍然会有横向滚动
- [Style] [tabs, tab-pane] 给el-tabs__item的style添加 padding-lert right !important 导致只有一个ElTabPane的时候下划线长度计算错误
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from element-plus.