1.数组里边相同元素提取成map,并以‘’,‘’分隔
例如:var arr = [{a:"xx",b:''xxx''},{a:"xxx",b:''xxxxx''},.....];
想要的结果 a = {''xx'',''xxx'',.....}; b = {''xxx'',''xxxxx'',.....};
var a = arr.map(function(item){
return item.a;
}).join(',');
以上同理b;
2.从数组中找出与当前id匹配的对象
例如:var arr = [{obja},{objb},{objc},....];
假设当前id为currentId 与arr里边的某一个对象的id匹配
则:当前匹配的对象
currentObj = $filter('filter')(arr,function(item){
return currentId === item.id;
})[0];
或者用underscore.js里边的_.filter方法
currentObj = _.filter(arr,function(item){
return currentId === item.id;
})[0];
3.两个数组值一一对应(对两个input输入值处理成数组并一一对应处理)
例如:var item.account=1;2;2;5; var item.deployPath=5;6;7,item.packageConfigDeployViews是数组有值修改/没值添加
下面实例是以那个数组长度长作为对应条件
if(item.packageConfigDeployViews){ var account = item.account.split(';'); var deployPath = item.deployPath.split(';'); if(account.length>=deployPath.length){ item.packageConfigDeployViews=_.map(account,function(val,index){ var obj=item.packageConfigDeployViews[index]; if(!_.isEmpty(obj)){ obj.account=val; obj.deployPath=deployPath[index]; return obj; }else{ return {account:val,deployPath:deployPath[index]}; } }); }else{ item.packageConfigDeployViews=_.map(deployPath,function(val,index){ var obj=item.packageConfigDeployViews[index]; if(!_.isEmpty(obj)){ obj.deployPath=val; obj.account=account[index]; return obj; }else{ return {deployPath:val,account:account[index]}; } }); } }else{ if(!_.isEmpty(item.account)&&(!_.isEmpty(item.deployPath))){ var account = item.account.split(';'); var deployPath = item.deployPath.split(';'); if(account.length>=deployPath.length){ item['packageConfigDeployViews']=_.map(account,function(val,index){ return {account:val,deployPath:deployPath[index]}; }); }else{ item['packageConfigDeployViews']=_.map(deployPath,function(val,index){ return {deployPath:val,account:account[index]}; }); } } }