Arrays 用于Javascript数组中不同类型密钥的ngIf
我有concerts数组和descriptions对象,我想从concerts中获取密钥并获取该字段的值Arrays 用于Javascript数组中不同类型密钥的ngIf,arrays,typescript,angular6,javascript-objects,Arrays,Typescript,Angular6,Javascript Objects,我有concerts数组和descriptions对象,我想从concerts中获取密钥并获取该字段的值 concerts: [ { key: "field_concerts_time", lbl: "Date" }, { key: ["field_concert_fromtime", "field_concert_totime"], lbl: "Time", concat: "to" },
concerts: [
{
key: "field_concerts_time",
lbl: "Date"
}, {
key: ["field_concert_fromtime", "field_concert_totime"],
lbl: "Time",
concat: "to"
}, {
key: "field_concerts_agereq",
lbl: "Age Requirements"
}, {
key: "field_concerts_dresscode",
lbl: "Dress Code"
}, {
key: "field_concerts_prices",
lbl: "Prices"
}
]
descriptions: {
"field_concerts_time": [
{
"value": "2019-09-16T00:00:00",
}
],
"field_concert_totime": [
{
"value": "1:00AM"
}
],
"field_concert_fromtime": [
{
"value": "7:30PM"
}
]
}
我得到了第一个索引的关键字段的值,并使用上面的标记从描述中获取了值。我希望此代码支持键:[field\u concert\u fromtime,field\u concert\u totime]给你。检查您是否已到达音乐会的时间对象。 如果是这样,则通过另外索引字段0和1将键作为数组处理
<p *ngFor="let otherdetail of otherdetailsarray">
<span *ngIf="descriptions[otherdetail.key][0].value !== null">
{{otherdetail.lbl}} :</span>
<span *ngIf="descriptions[otherdetail.key][0].value !== null &&
descriptions[otherdetail.key][0].value !== undefined">
{{descriptions[otherdetail.key][0].value }}</span>
</p>
这应该可以解决问题。对不起,我不得不再次更正代码,因为有一个输入错误。现在应该可以工作了。
<p *ngFor="let otherdetail of otherdetailsarray">
<span *ngIf="descriptions[otherdetail.key][0].value !== null">
{{otherdetail.lbl}} :</span>
<span *ngIf="otherdetail.lbl !== 'Time' &&
descriptions[otherdetail.key][0].value !== null &&
descriptions[otherdetail.key][0].value !== undefined">
{{descriptions[otherdetail.key][0].value }}
</span>
<span *ngIf="otherdetail.lbl == 'Time' &&
descriptions[otherdetail.key[0]][0].value &&
descriptions[otherdetail.key[1]][0].value">
{{descriptions[otherdetail.key[0]][0].value }} {{otherdetail.concat}}
{{descriptions[otherdetail.key[1]][0].value }}
</span>
</p>