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) {
|
||||
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 => {
|
||||
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 newTitle = typeof title === 'function' ? title(this.$createElement) : title;
|
||||
if (!newLabel && scopedSlots.label && $scopedSlots[scopedSlots.label]) {
|
||||
|
@ -76,7 +89,9 @@ const TreeSelect = {
|
|||
const treeNodeProps = {
|
||||
...item,
|
||||
title: newTitle || newLabel,
|
||||
value,
|
||||
dataRef: item,
|
||||
key,
|
||||
};
|
||||
if (children) {
|
||||
return { ...treeNodeProps, children: this.updateTreeData(children) };
|
||||
|
|
|
@ -53,4 +53,5 @@ export const TreeSelectProps = () => ({
|
|||
treeDefaultExpandedKeys: PropTypes.array,
|
||||
treeNodeFilterProp: PropTypes.string,
|
||||
treeNodeLabelProp: PropTypes.string,
|
||||
replaceFields: PropTypes.object.def({}),
|
||||
});
|
||||
|
|
|
@ -222,6 +222,8 @@ export declare class TreeSelect extends AntdComponent {
|
|||
|
||||
clearIcon?: any;
|
||||
|
||||
replaceFields: object;
|
||||
|
||||
/**
|
||||
* remove focus
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue