对obj数组中categoryName去重,如果一样得就把item放入data数组
// 伪代码
{categoryName:data[]}
最后返回[data1,data2......]
```
searchDataFilter:function(obj,uniqueKey,categoryCode){
var filterArr = [];
var hash={};
var resMap = obj.reduce(function (item,next) {
if(hash[next[uniqueKey]]){
item[next[uniqueKey]].table.push(next);
}else{
hash[next[uniqueKey]] =true
var tables = [];
tables.push(next);
var one = {
categoryName:next[uniqueKey],
categoryCode: next[categoryCode],
table: tables
}
item[next[uniqueKey]] = one;
}
return item;
},{});
for(var keyin resMap){
filterArr.push(resMap[key]);
};
return filterArr;
}
```
网友评论