Skip to content

Commit 4cc762d

Browse files
committed
feat: treeSelect add replaceFields #2253
1 parent 0466a39 commit 4cc762d

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

Diff for: antdv-demo

Diff for: components/tree-select/index.jsx

+16-1
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,21 @@ const TreeSelect = {
6363
},
6464
updateTreeData(treeData) {
6565
const { $scopedSlots } = this;
66+
const defaultFields = {
67+
children: 'children',
68+
title: 'title',
69+
key: 'key',
70+
label: 'label',
71+
value: 'value',
72+
};
73+
const replaceFields = { ...defaultFields, ...this.$props.replaceFields };
6674
return treeData.map(item => {
67-
const { label, title, scopedSlots = {}, children } = item;
75+
const { scopedSlots = {} } = item;
76+
const label = item[replaceFields.label];
77+
const title = item[replaceFields.title];
78+
const value = item[replaceFields.value];
79+
const key = item[replaceFields.key];
80+
const children = item[replaceFields.children];
6881
let newLabel = typeof label === 'function' ? label(this.$createElement) : label;
6982
let newTitle = typeof title === 'function' ? title(this.$createElement) : title;
7083
if (!newLabel && scopedSlots.label && $scopedSlots[scopedSlots.label]) {
@@ -76,7 +89,9 @@ const TreeSelect = {
7689
const treeNodeProps = {
7790
...item,
7891
title: newTitle || newLabel,
92+
value,
7993
dataRef: item,
94+
key,
8095
};
8196
if (children) {
8297
return { ...treeNodeProps, children: this.updateTreeData(children) };

Diff for: components/tree-select/interface.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ export const TreeSelectProps = () => ({
5353
treeDefaultExpandedKeys: PropTypes.array,
5454
treeNodeFilterProp: PropTypes.string,
5555
treeNodeLabelProp: PropTypes.string,
56+
replaceFields: PropTypes.object.def({}),
5657
});

Diff for: types/tree-select.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ export declare class TreeSelect extends AntdComponent {
222222

223223
clearIcon?: any;
224224

225+
replaceFields: object;
226+
225227
/**
226228
* remove focus
227229
*/

0 commit comments

Comments
 (0)