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"
}
]
}
У меня есть массив концертов и объект описания, я хочу взять «ключ» из концертов и получить значение для этого поля.
<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>
Я получил значение для ключа 1-го индекса «field_concerts_time» и взял значение из описания, используя вышеуказанные теги. Я хочу, чтобы этот код поддерживал "key: ["field_concert_fromtime", "field_concert_totime"]"



Ну вот. Проверьте, достигли ли вы объекта Времени концерта. Если это так, обработайте ключ как массив, дополнительно проиндексировав поля 0 и 1.
<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>
Это должно сработать.
Извините, мне пришлось еще раз исправить мой код, так как была опечатка. Должно работать сейчас.