获取后台的数据 取出需要的数据以参数形式(arrobj2)传给后台
let arrobj=[{name:"aaa",age:"10"},{name:"bbb",age:"11"},{name:"ccc",age:"12"},{name:"ddd",age:"10"},{name:"eee",age:"11"}]
let arrobj2=[{name:["aaa","ddd"],age:"10"},{name:["bbb","eee"],age:"11"},{name:["ccc"],age:"12"}]
例如:将arrobj 转换合并为arrobj2
sortArr(arr, str) {
let _arr = [],
_t = [],
// 临时的变量
_tmp;
// 按照特定的参数将数组排序将具有相同值得排在一起
arr = arr.sort(function(a, b) {
let s = a[str],
t = b[str];
return s < t ? -1 : 1;
});
if ( arr.length ){
_tmp = arr[0][str];
}
// console.log( arr );
// 将相同类别的对象添加到统一个数组
for (let i in arr) {
// console.log( _tmp);
if ( arr[i][str] === _tmp ){
// console.log(_tmp)
_t.push( arr[i] );
} else {
_tmp = arr[i][str];
_arr.push( _t );
_t = [arr[i]];
}
}
// 将最后的内容推出新数组
_arr.push( _t );
return _arr;
},
secondchange(val){
let arr2=[]
let arr1=[]
let obj2={userId:[],platformId:"",i18nValue:"2"}
// 将后台获取的数据的遍历取出需要的数据
for(let i=0;i<val.length;i++){
let obj={}
obj.userId=val[i].userId
obj.platformId=val[i].platformId
arr1.push(obj)
}
//此时 arr1=[{name:"aaa",age:"10"},{name:"bbb",age:"11"},{name:"ccc",age:"12"},{name:"ddd",age:"10"},{name:"eee",age:"11"}]
//this.sortArr(要筛选的数组,要判断的属性名)
let arrz=this.sortArr(arr1,"platformId")
//
arrz.forEach(item=>{
obj2={userId:[],platformId:"",i18nValue:"2"}
for(let i=0;i<item.length;i++){
obj2.userId.push(item[i].userId)
obj2.platformId=item[i].platformId
}
arr2.push(obj2)
})
// console.log(arr2,"020202020")
this.secheckedids=arr2
},