fix: treeSelect not support dataRef #712
parent
9837004222
commit
e5020f7eb8
|
@ -63,25 +63,28 @@ const TreeSelect = {
|
||||||
onChange() {
|
onChange() {
|
||||||
this.$emit('change', ...arguments);
|
this.$emit('change', ...arguments);
|
||||||
},
|
},
|
||||||
updateTreeData(list = []) {
|
updateTreeData(treeData) {
|
||||||
for (let i = 0, len = list.length; i < len; i++) {
|
const { $scopedSlots } = this;
|
||||||
const { label, title, scopedSlots = {}, children } = list[i];
|
return treeData.map(item => {
|
||||||
const { $scopedSlots } = this;
|
const { label, title, scopedSlots = {}, children } = item;
|
||||||
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]) {
|
||||||
newLabel = $scopedSlots.label(list[i]);
|
newLabel = $scopedSlots.label(item);
|
||||||
}
|
}
|
||||||
if (!newTitle && scopedSlots.title && $scopedSlots[scopedSlots.title]) {
|
if (!newTitle && scopedSlots.title && $scopedSlots[scopedSlots.title]) {
|
||||||
newTitle = $scopedSlots.title(list[i]);
|
newTitle = $scopedSlots.title(item);
|
||||||
}
|
}
|
||||||
const item = {
|
const treeNodeProps = {
|
||||||
// label: newLabel,
|
...item,
|
||||||
title: newTitle || newLabel,
|
title: newTitle || newLabel,
|
||||||
|
dataRef: item,
|
||||||
};
|
};
|
||||||
this.updateTreeData(children || []);
|
if (children) {
|
||||||
Object.assign(list[i], item);
|
return { ...treeNodeProps, children: this.updateTreeData(children) };
|
||||||
}
|
}
|
||||||
|
return treeNodeProps;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
renderTreeSelect(locale) {
|
renderTreeSelect(locale) {
|
||||||
const props = getOptionProps(this);
|
const props = getOptionProps(this);
|
||||||
|
@ -105,7 +108,10 @@ const TreeSelect = {
|
||||||
]);
|
]);
|
||||||
let suffixIcon = getComponentFromProp(this, 'suffixIcon');
|
let suffixIcon = getComponentFromProp(this, 'suffixIcon');
|
||||||
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon;
|
suffixIcon = Array.isArray(suffixIcon) ? suffixIcon[0] : suffixIcon;
|
||||||
this.updateTreeData(props.treeData || []);
|
let treeData = props.treeData;
|
||||||
|
if (treeData) {
|
||||||
|
treeData = this.updateTreeData(treeData);
|
||||||
|
}
|
||||||
const cls = {
|
const cls = {
|
||||||
[`${prefixCls}-lg`]: size === 'large',
|
[`${prefixCls}-lg`]: size === 'large',
|
||||||
[`${prefixCls}-sm`]: size === 'small',
|
[`${prefixCls}-sm`]: size === 'small',
|
||||||
|
@ -128,20 +134,23 @@ const TreeSelect = {
|
||||||
);
|
);
|
||||||
|
|
||||||
const VcTreeSelectProps = {
|
const VcTreeSelectProps = {
|
||||||
props: {
|
props: Object.assign(
|
||||||
switcherIcon: this.renderSwitcherIcon,
|
{
|
||||||
inputIcon,
|
switcherIcon: this.renderSwitcherIcon,
|
||||||
removeIcon,
|
inputIcon,
|
||||||
clearIcon,
|
removeIcon,
|
||||||
...rest,
|
clearIcon,
|
||||||
getPopupContainer: getPopupContainer || getContextPopupContainer,
|
...rest,
|
||||||
dropdownClassName: classNames(dropdownClassName, `${prefixCls}-tree-dropdown`),
|
getPopupContainer: getPopupContainer || getContextPopupContainer,
|
||||||
prefixCls,
|
dropdownClassName: classNames(dropdownClassName, `${prefixCls}-tree-dropdown`),
|
||||||
dropdownStyle: { maxHeight: '100vh', overflow: 'auto', ...dropdownStyle },
|
prefixCls,
|
||||||
treeCheckable: checkable,
|
dropdownStyle: { maxHeight: '100vh', overflow: 'auto', ...dropdownStyle },
|
||||||
notFoundContent: notFoundContent || locale.notFoundContent,
|
treeCheckable: checkable,
|
||||||
__propsSymbol__: Symbol(),
|
notFoundContent: notFoundContent || locale.notFoundContent,
|
||||||
},
|
__propsSymbol__: Symbol(),
|
||||||
|
},
|
||||||
|
treeData ? { treeData } : {},
|
||||||
|
),
|
||||||
class: cls,
|
class: cls,
|
||||||
on: { ...this.$listeners, change: this.onChange },
|
on: { ...this.$listeners, change: this.onChange },
|
||||||
ref: 'vcTreeSelect',
|
ref: 'vcTreeSelect',
|
||||||
|
|
Loading…
Reference in New Issue