-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
a-directory-tree 使用 treeData 时无法正确的全部展开子节点 #2858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
定位到 var treeProps = {
props: (0, _extends3['default'])({
icon: getIcon
}, props, {
prefixCls: prefixCls,
// expandedKeys: expandedKeys, // 通过调试,删除改行代码是可以展开全部节点的
selectedKeys: selectedKeys,
switcherIcon: (0, _propsUtil.getComponentFromProp)(this, 'switcherIcon')
}),
ref: 'tree',
'class': prefixCls + '-directory',
on: (0, _extends3['default'])({}, (0, _omit2['default'])(listeners, ['update:selectedKeys']), {
select: this.onSelect,
click: this.onClick,
dblclick: this.onDoubleClick,
expand: this.onExpand
})
};
function getFullKeyListByTreeData(treeData) {
console.log(treeData)
var keys = [];
(treeData || []).forEach(function (item) {
keys.push(item.key); // 此处写死了,本应该我们替换了默认的键名 key ,这里应该使用 替换好的
if (item.children) {
keys = [].concat((0, _toConsumableArray3['default'])(keys), (0, _toConsumableArray3['default'])(getFullKeyListByTreeData(item.children)));
}
});
return keys;
} |
我将我的组件代码修改如下,是可以支持默认展开功能,主要还是自定义的 replaceFields 在源代码中没有应用 <template>
<a-directory-tree
v-model="checkedKeys"
v-bind="$attrs"
v-on="$listeners"
checkable
defaultExpandAll
:tree-data="directoryTreeData"
:selectable="false"
:replaceFields="replaceFields"
>
<!-- 官方slots插槽 " -->
<template v-for="slot in Object.keys($slots)" #[slot]>
<slot :name="slot" />
</template>
</a-directory-tree>
</template>
<script>
export default {
name: 'Ant_DirectoryTree',
props: {
value: {
type: Array,
default: () => []
},
dataSource: {
type: Array,
default: () => []
},
replaceFields: {
type: Object,
default: () => {
return {
children: 'children',
title: 'name',
key: 'id'
}
}
}
},
computed: {
checkedKeys: {
get() {
return this.value
},
set(val) {
this.$emit('input', val)
}
},
directoryTreeData: {
get () {
const { dataSource } = this
const {
children: CHILDREN = 'children',
key: KEY = 'key'
} = this.replaceFields
const setIsLeaf = (val) => {
if (val[CHILDREN] && val[CHILDREN].length) {
val[CHILDREN].map(item => {
setIsLeaf(item)
})
} else {
val.isLeaf = true
val.key = val[KEY]
}
}
dataSource.map(item => {
return setIsLeaf(item)
})
return dataSource
}
}
}
}
</script>
|
如果已经定位问题,欢迎给我们提交 pr 感谢 |
这个问题我也撞见了。希望尽快合并PR. |
原谅我不知道怎么做 PR,可以看下我的做的 更改,这样的更改是可以支持了 https://github.com/vxhly/ant-design-vue/commit/9e5ce3ed517779254eaedaa4465020936c647e55 |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Version
1.6.5
Environment
Windows,Google Chrome ,[email protected]
Reproduction link
Steps to reproduce
对 a-directory-tree 配置了 treeData 和 default-expand-all 两个配置项
What is expected?
能够完全展开子节点
What is actually happening?
不能完全展开子节点
The text was updated successfully, but these errors were encountered: