|
@@ -8,9 +8,12 @@ const _ = require('lodash'); |
|
@@ -8,9 +8,12 @@ const _ = require('lodash'); |
8
|
|
8
|
|
9
|
/**
|
9
|
/**
|
10
|
* 处理 以风格的数据
|
10
|
* 处理 以风格的数据
|
|
|
11
|
+ * 风格1:
|
11
|
* [
|
12
|
* [
|
12
|
* {filter_attribute: value}
|
13
|
* {filter_attribute: value}
|
13
|
* ]
|
14
|
* ]
|
|
|
15
|
+ * 风格2:
|
|
|
16
|
+ * {filter_attribute: value}
|
14
|
*
|
17
|
*
|
15
|
* 处理结果
|
18
|
* 处理结果
|
16
|
* [
|
19
|
* [
|
|
@@ -22,18 +25,32 @@ let verboseAttrHandler = (filterField, dataArr) => { |
|
@@ -22,18 +25,32 @@ let verboseAttrHandler = (filterField, dataArr) => { |
22
|
let result = [];
|
25
|
let result = [];
|
23
|
let re = new RegExp(`^${filterField}_`);
|
26
|
let re = new RegExp(`^${filterField}_`);
|
24
|
|
27
|
|
25
|
- dataArr.forEach(obj => {
|
28
|
+ // 处理 {filter_attribute: value}
|
|
|
29
|
+ function handlerAttrObj(obj) {
|
26
|
let item = {};
|
30
|
let item = {};
|
27
|
let keys = Object.keys(obj);
|
31
|
let keys = Object.keys(obj);
|
28
|
|
32
|
|
29
|
- keys.forEach(key=>{
|
33
|
+ keys.forEach(key => {
|
30
|
let newKey = key.replace(re, '');
|
34
|
let newKey = key.replace(re, '');
|
31
|
|
35
|
|
32
|
item[newKey] = obj[key];
|
36
|
item[newKey] = obj[key];
|
33
|
});
|
37
|
});
|
|
|
38
|
+ return item;
|
|
|
39
|
+ }
|
34
|
|
40
|
|
35
|
- result.push(item);
|
41
|
+ if (_.isPlainObject(dataArr)) {
|
|
|
42
|
+ // 风格2
|
|
|
43
|
+ let attr = handlerAttrObj(dataArr);
|
|
|
44
|
+
|
|
|
45
|
+ result.push(attr);
|
|
|
46
|
+ } else {
|
|
|
47
|
+ // 风格1
|
|
|
48
|
+ dataArr.forEach(obj => {
|
|
|
49
|
+ let attr = handlerAttrObj(obj);
|
|
|
50
|
+
|
|
|
51
|
+ result.push(attr);
|
36
|
});
|
52
|
});
|
|
|
53
|
+ }
|
37
|
|
54
|
|
38
|
return result;
|
55
|
return result;
|
39
|
};
|
56
|
};
|
|
@@ -60,7 +77,7 @@ let keyIdHandler = (filterField, obj) => { |
|
@@ -60,7 +77,7 @@ let keyIdHandler = (filterField, obj) => { |
60
|
const keys = Object.keys(obj);
|
77
|
const keys = Object.keys(obj);
|
61
|
|
78
|
|
62
|
keys.sort();
|
79
|
keys.sort();
|
63
|
- keys.forEach(key=> {
|
80
|
+ keys.forEach(key => {
|
64
|
let item = {};
|
81
|
let item = {};
|
65
|
|
82
|
|
66
|
item.id = key;
|
83
|
item.id = key;
|