修复select 选择顺序没办法控制的问题

This commit is contained in:
liaoxuezhi 2019-12-19 12:17:14 +08:00
parent a86aeb7e35
commit c4b6d5afb7

View File

@ -16,7 +16,8 @@ import {
isArrayChildrenModified, isArrayChildrenModified,
isObject, isObject,
createObject, createObject,
isObjectShallowModified isObjectShallowModified,
findTree
} from '../utils/helper'; } from '../utils/helper';
import {flattenTree} from '../utils/helper'; import {flattenTree} from '../utils/helper';
import {IRendererStore} from '.'; import {IRendererStore} from '.';
@ -151,33 +152,21 @@ export const FormItemStore = types
const selectedOptions: Array<any> = []; const selectedOptions: Array<any> = [];
flattenTree(self.filteredOptions).forEach((item: any) => { selected.forEach(item => {
let idx = findIndex(selected, seleced => { const matched = findTree(self.filteredOptions, option => {
return isObject(seleced) return isObject(item)
? seleced === item[self.valueField || 'value'] ? item === option[self.valueField || 'value']
: String(item[self.valueField || 'value']) === String(seleced); : String(option[self.valueField || 'value']) === String(item);
}); });
if (~idx) { if (matched) {
selected.splice(idx, 1); selectedOptions.push(matched);
selectedOptions.push(item); } else if (item) {
} selectedOptions.push({
});
selected.forEach((item, index) => {
let unMatched = (value && value[index]) || item;
if (
unMatched &&
(typeof unMatched === 'string' || typeof unMatched === 'number')
) {
unMatched = {
[self.valueField || 'value']: item, [self.valueField || 'value']: item,
[self.labelField || 'label']: item [self.labelField || 'label']: item
}; });
} }
unMatched && selectedOptions.push(unMatched);
}); });
return selectedOptions; return selectedOptions;