Skip to content

TreeSelect setting showCheckedStrategy=SHOW_CHILD is invalid, the parent node is still selected #3811

@chennh

Description

@chennh
  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

1.7.3

Environment

[MacOS 11.1] [Chrome 89.0.4389.90] [Vue 2.6.12] [ant-design-vue 1.7.4]

Reproduction link

https://github.com/vueComponent/ant-design-vue/issues

Steps to reproduce

TreeSelect组件设置
[showCheckedStrategy=SHOW_CHILD]
[treeCheckable=true]

What is expected?

期望选中的只有叶子节点

What is actually happening?

父节点也被选中了


看了一下ant-design-vue/es/vc-tree-select的源码,在vc-tree-select/src/util.js断点方法formatSelectorValue,其中一段代码有些疑问
var hierarchyList = flatToHierarchy(valueList.map(function (_ref3) {
var value = _ref3.value;
return valueEntities[value];
}));

方法flatToHierarchy中删除了clone的children属性
var parsedList = positionList.slice().map(function (entity) {
var clone = _extends({}, entity, {
fields: entity.pos.split('-')
});
delete clone.children;
return clone;
});

回到formatSelectorValue方法接下去部分代码
if (showCheckedStrategy === SHOW_CHILD) {
// Only get the children checked value
var targetValueList = [];

// Find the leaf children
var traverse = function traverse(_ref5) {
var node = _ref5.node,
children = _ref5.children;

var value = getPropsData(node).value;
if (!children || children.length === 0) {
targetValueList.push({
label: getLabel(values[value], valueEntities[value], treeNodeLabelProp),
value: value
});
return;
}

children.forEach(function (entity) {
traverse(entity);
});
};

hierarchyList.forEach(function (entity) {
traverse(entity);
});

return targetValueList;
}
}

这里根据对象的children属性判断是否为叶子节点,感觉逻辑是不合理的?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions