根据后端返回的数据,过滤掉正常的数据,获取异常的数据展示
后端数据如下:
let data = {
a: {
id: 1,
result: {
status: "error",
code: "HTTP_400",
message: "missing parameter"
}
},
b: {
id: 2,
result: {
status: "success",
code: "ok",
data: null
}
},
c: {
id: 3,
result: {
status: "success",
code: "ok",
data: null
}
}
};
处理方法如下:
function dealErrData(data) {
let keys = Object.keys(data);
let errData = [];
keys.forEach(item => {
if (data[item].result.code !== "ok") {
errData.push({ name: item, data: data[item] });
}
});
return errData;
}
console.log("errData:", dealErrData(data));