element icon indicating copy to clipboard operation
element copied to clipboard

[Feature Request] 请问Tree树形控件怎么实现只能单选?

Open MrYuJ opened this issue 9 years ago • 5 comments

Existing Component

是

Component Name

tree

Description

Tree树形控件怎么实现只能单选?如果不能,是否未来可以加上?而且文档里的current-change事件并不能触发。

MrYuJ avatar Apr 14 '17 11:04 MrYuJ

这个功能自己用一些丑陋的方法实现了。 大概是 1.保存一个变量用于判断节点的选中状态的改变是否由点击事件触发isClickChangeCheckbox 2.为el-checkbox绑定点击事件,在点击checkbox时改变isClickChangeCheckbox为true this.$nextTick(() => { $(this.$el).find('.el-checkbox').on('click', function () { isClickChangeCheckbox = true; }) }) 3.节点选中状态回调中 /** * 节点选中状态变化回调 * @param nodeData * @param isChecked */ checkChange(nodeData, isChecked) { if (isClickChangeCheckbox && isChecked) { this.$refs.organizationTree.setCheckedKeys([]); this.$refs.organizationTree.setCheckedNodes([nodeData]); } isClickChangeCheckbox = false; }

MrYuJ avatar Apr 15 '17 01:04 MrYuJ

@MrYuJ 单选是刚需。。 我最近在项目中按照el-tree的样子整了一个,不能总等着别人来贡献啊。。还是得自己造 参考:https://github.com/wilsonIs/treeSelect

wilsonIs avatar May 16 '17 13:05 wilsonIs

@wilsonIs 请教一个问题, tree组件如果勾上父级,此时该父级下所有节点自动选上. 此时怎么收集所有勾选了的ID,value啊, 貌似tree组件没有这个数据收集映射功能. 我也看了你写的组件。

ghost avatar Sep 04 '17 09:09 ghost

@1657413883 才看到这个。。。 element是有实现这个功能的,通过getCheckedNodes获取所有勾选中的节点数据。 我自己写的组件没有做勾选父节点自动选中其子节点的功能,其实就是遍历下子节点就可以实现。。。

wilsonIs avatar Sep 22 '17 02:09 wilsonIs

I think the feature is customized by demand. The best practice maybe modify el-tree and do it yourself.

csvwolf avatar Nov 06 '18 08:11 csvwolf