【发布时间】:2019-03-11 11:40:31
【问题描述】:
我有一个包含以下内容的 config.ts 文件:
export const keyOrders: {} = {
"aa": { active: true, order: 0 },
"bb": { active: true, order: 1 },
"cc": { active: true, order: 2 },
"dd": { active: true, order: 3 },
"ee": { active: false, order: 4 },
"ff": { active: true, order: 5 }
};
如果 active 为真,我会尝试推送到数组。我尝试过以下代码,如果 active 为 true,则按下键,但如果 active 为 false,则返回“未定义”
public keys = [];
public keyOrders = keyOrders;
ngOnInit() {
this.keys = Object.entries(this.keyOrders).map((a: any) => {
if(a[1].active == 'true') {
return a[0];
}
});
}
【问题讨论】:
标签: javascript angular typescript