forked from apache/incubator-weex-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
49 lines (43 loc) · 1010 Bytes
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Utils from '../utils';
export function getCities (list, showDesc = false) {
if (list && list.length > 0) {
const result = list.map((v) => {
const o = Object.assign({}, v);
if (o.suggestName) {
o.name = o.suggestName;
}
if (o.stationName && !o.name) {
o.name = o.stationName;
}
if (o.cityName && !o.name) {
o.name = o.cityName;
}
if (o.code && showDesc) {
o.desc = o.code;
}
return o;
});
return result;
} else {
return [];
}
}
export function query (source, text) {
let res = [];
res = source.filter(item => {
const arr = [];
let isHave = false;
Object.keys(item).forEach(prop => {
const itemStr = item[prop];
Utils.isString(itemStr) && itemStr.split(',').forEach(val => {
arr.push(val);
});
});
arr.some(val => {
isHave = new RegExp('^' + text).test(val);
return isHave;
});
return isHave;
});
return res;
}