jquery实现对象数组 筛选出每条记录中的特定属性字段
直接上图:
源码:
/**
* 对后端返回的数据,筛选出符合报表的列项,多余的列项去除
*/
function filterParams(data) {
if (data.length > 0) {
this.reportData = data;
let result = [];
this.reportData.map((item) => result.push({
Name: item.Name,
MarketCodeName: item.MarketCodeName,
Sex: item.Sex,
IdentityTypeName: item.IdentityTypeName,
IdentityNo: item.IdentityNo,
CountryName: item.CountryName,
RoomNo: item.RoomNo,
ArrivalDate: item.ArrivalDate,
DepartureDate: item.DepartureDate,
RoomRate: item.RoomRate
}));
return result;
} else {
return data;
}
//对于一个筛选需要的字段,也可以采用下面的方法遍历
let resultData = [];
$.each(data, function (i, item) {
let obj = new Object;
obj.Name = item.Name,
obj.MarketCodeName = item.MarketCodeName,
obj.Sex = item.Sex,
obj.IdentityTypeName = item.IdentityTypeName,
obj.IdentityNo = item.IdentityNo,
obj.CountryName = item.CountryName,
obj.RoomNo = item.RoomNo,
obj.ArrivalDate = item.ArrivalDate,
obj.DepartureDate = item.DepartureDate,
obj.RoomRate = item.RoomRate;
resultData.push(obj);
});
return resultData;
}