【发布时间】:2020-01-31 13:48:02
【问题描述】:
要从对象中删除空行,需要通用解决方案。
该对象包含一个列表。
这是我要检查的示例对象
{
"test": {
"id": null
},
"testName": null,
"specimen": {
"id": null
},
"specimenName": null,
"collectionDate": null,
"resultDate": null,
"result": null,
"finding": null,
"resultValue": null
}
这个我试过了,但是里面有列表的时候就不行了。
purgeEmptyRows(obj: any) : boolean {
let isEmpty = false;
Object.keys(obj).forEach(key => {
if (!obj[key]) {
isEmpty = false;
}else {
return true;
}
})
return isEmpty;
}
【问题讨论】:
-
我不确定你的意思。如果所有子节点都为空,则父节点 isEmpty = true 对吗?
-
对象不为空,该对象中的每个元素都为空。正如我在问题中提到的那样。
-
看看stackoverflow.com/a/38340374/2358409。这应该很容易适应
null值。 -
那么你的结果会像这样吗? {“测试”:{},“样本”:{},}
标签: angularjs typescript angular6