text autoComplete 重新加载时不丢失 label 信息

This commit is contained in:
liaoxuezhi 2019-06-05 16:54:39 +08:00
parent bc585c9c7f
commit f1c5c36fca
3 changed files with 29 additions and 21 deletions

View File

@ -1,31 +1,31 @@
const db = [
{
"label": "liaoxuezhi",
"label": "zhugeliang",
"value": "1"
},
{
"label": "zhangjun08",
"label": "zhongwuyan",
"value": "2"
},
{
"label": "zhangtao07",
"label": "buzhihuowu",
"value": "3"
},
{
"label": "wuduoyi",
"label": "zhongkui",
"value": "4"
},
{
"label": "liuyiming04",
"label": "luna",
"value": "5"
},
{
"label": "zhangzhuobin",
"label": "wangzhaojun",
"value": "6"
}
];

View File

@ -1,32 +1,32 @@
const db = [
{
"label": "liaoxuezhi",
"value": "liaoxuezhi"
"label": "诸葛亮",
"value": "zhugeliang"
},
{
"label": "zhangjun08",
"value": "zhangjun08"
"label": "王昭君",
"value": "wangzhaojun"
},
{
"label": "zhangtao07",
"value": "zhangtao07"
"label": "钟馗",
"value": "zhongkui"
},
{
"label": "wuduoyi",
"value": "wuduoyi"
"label": "露娜",
"value": "luna"
},
{
"label": "liuyiming04",
"value": "liuyiming04"
"label": "钟无艳",
"value": "zhongwuyan"
},
{
"label": "zhangzhuobin",
"value": "zhangzhuobin"
"label": "花木兰",
"value": "huamulan"
}
];
@ -38,7 +38,7 @@ module.exports = function(req, res) {
status: 0,
msg: '',
data: term ? db.filter(function(item) {
return term ? ~item.label.indexOf(term) : false;
return term ? ~item.label.indexOf(term) || ~item.value.indexOf(term) : false;
}) : db
});
}

View File

@ -30,6 +30,7 @@ import {
} from '../utils/helper';
import { IRendererStore } from ".";
import { normalizeOptions } from "../components/Select";
import find = require('lodash/find');
interface IOption {
value?: string | number | null;
@ -325,8 +326,9 @@ export const FormItemStore = types
return;
}
options = options.filter(item => item);
const originOptions = self.options.concat();
options.length ? self.options.replace(options) : self.options.clear();
syncOptions();
syncOptions(originOptions);
}
let loadCancel:Function | null = null;
@ -385,7 +387,7 @@ export const FormItemStore = types
}
});
function syncOptions() {
function syncOptions(originOptions?:Array<any>) {
if (!self.options.length && typeof self.value === 'undefined') {
self.selectedOptions = [];
self.filteredOptions = [];
@ -445,6 +447,12 @@ export const FormItemStore = types
[self.labelField || 'label']: item,
__unmatched: true
}
const orgin:any = originOptions && find(originOptions, target => String(target[self.valueField || 'value']) === String(item));
if (orgin) {
unMatched[self.labelField || 'label'] = orgin[self.labelField || 'label'];
}
}
unMatched && selectedOptions.push(unMatched);