feat: treeSelect add replaceFields #2253
parent
0466a39b5a
commit
4cc762d6cb
|
@ -1 +1 @@
|
||||||
Subproject commit 7da5429bd5556f6a87c065f6675b963e45f7a83b
|
Subproject commit 6213d13ef5f287b16a05ff5509b444a662570944
|
|
@ -63,8 +63,21 @@ const TreeSelect = {
|
||||||
},
|
},
|
||||||
updateTreeData(treeData) {
|
updateTreeData(treeData) {
|
||||||
const { $scopedSlots } = this;
|
const { $scopedSlots } = this;
|
||||||
|
const defaultFields = {
|
||||||
|
children: 'children',
|
||||||
|
title: 'title',
|
||||||
|
key: 'key',
|
||||||
|
label: 'label',
|
||||||
|
value: 'value',
|
||||||
|
};
|
||||||
|
const replaceFields = { ...defaultFields, ...this.$props.replaceFields };
|
||||||
return treeData.map(item => {
|
return treeData.map(item => {
|
||||||
const { label, title, scopedSlots = {}, children } = item;
|
const { scopedSlots = {} } = item;
|
||||||
|
const label = item[replaceFields.label];
|
||||||
|
const title = item[replaceFields.title];
|
||||||
|
const value = item[replaceFields.value];
|
||||||
|
const key = item[replaceFields.key];
|
||||||
|
const children = item[replaceFields.children];
|
||||||
let newLabel = typeof label === 'function' ? label(this.$createElement) : label;
|
let newLabel = typeof label === 'function' ? label(this.$createElement) : label;
|
||||||
let newTitle = typeof title === 'function' ? title(this.$createElement) : title;
|
let newTitle = typeof title === 'function' ? title(this.$createElement) : title;
|
||||||
if (!newLabel && scopedSlots.label && $scopedSlots[scopedSlots.label]) {
|
if (!newLabel && scopedSlots.label && $scopedSlots[scopedSlots.label]) {
|
||||||
|
@ -76,7 +89,9 @@ const TreeSelect = {
|
||||||
const treeNodeProps = {
|
const treeNodeProps = {
|
||||||
...item,
|
...item,
|
||||||
title: newTitle || newLabel,
|
title: newTitle || newLabel,
|
||||||
|
value,
|
||||||
dataRef: item,
|
dataRef: item,
|
||||||
|
key,
|
||||||
};
|
};
|
||||||
if (children) {
|
if (children) {
|
||||||
return { ...treeNodeProps, children: this.updateTreeData(children) };
|
return { ...treeNodeProps, children: this.updateTreeData(children) };
|
||||||
|
|
|
@ -53,4 +53,5 @@ export const TreeSelectProps = () => ({
|
||||||
treeDefaultExpandedKeys: PropTypes.array,
|
treeDefaultExpandedKeys: PropTypes.array,
|
||||||
treeNodeFilterProp: PropTypes.string,
|
treeNodeFilterProp: PropTypes.string,
|
||||||
treeNodeLabelProp: PropTypes.string,
|
treeNodeLabelProp: PropTypes.string,
|
||||||
|
replaceFields: PropTypes.object.def({}),
|
||||||
});
|
});
|
||||||
|
|
|
@ -222,6 +222,8 @@ export declare class TreeSelect extends AntdComponent {
|
||||||
|
|
||||||
clearIcon?: any;
|
clearIcon?: any;
|
||||||
|
|
||||||
|
replaceFields: object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove focus
|
* remove focus
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue