Browse Source

feat: treeSelect add replaceFields #2253

pull/2284/head
tanjinzhou 5 years ago
parent
commit
4cc762d6cb
  1. 2
      antdv-demo
  2. 17
      components/tree-select/index.jsx
  3. 1
      components/tree-select/interface.jsx
  4. 2
      types/tree-select.d.ts

2
antdv-demo

@ -1 +1 @@
Subproject commit 7da5429bd5556f6a87c065f6675b963e45f7a83b
Subproject commit 6213d13ef5f287b16a05ff5509b444a662570944

17
components/tree-select/index.jsx

@ -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) };

1
components/tree-select/interface.jsx

@ -53,4 +53,5 @@ export const TreeSelectProps = () => ({
treeDefaultExpandedKeys: PropTypes.array,
treeNodeFilterProp: PropTypes.string,
treeNodeLabelProp: PropTypes.string,
replaceFields: PropTypes.object.def({}),
});

2
types/tree-select.d.ts vendored

@ -222,6 +222,8 @@ export declare class TreeSelect extends AntdComponent {
clearIcon?: any;
replaceFields: object;
/**
* remove focus
*/

Loading…
Cancel
Save