html - 试图打印一个包含对象数组的对象 Html
问题描述
我正在尝试打印此对象:
export class Ricette {
nome: string;
azioni: {tempo: number, azione: string}[][]
}
export const RICETTE : Ricette[] = [
{
nome: 'Alici',
azioni: [[
{tempo: 500, azione: 'scongela'},
{tempo: 60, azione: 'nulla'}
]]
},
{
nome: 'Baccalà',
azioni: [[
{tempo: 500, azione: 'scongela'}],
[
{tempo: 210, azione: 'immerso'},
{tempo: 210, azione: 'cestello su'},
{tempo: 30, azione: 'immerso'}
]
]
},
{
nome: 'Hamburger',
azioni: [[
{tempo: 500, azione: 'scongela'}],
[
{tempo: 210, azione: 'immerso'},
{tempo: 210, azione: 'cestello su'},
{tempo: 30, azione: 'immerso'}
]
]
}
];
ricette = RICETTE;
在一个 html 文件中。
数组azioni[]
将在 的每个项目中具有不同的长度ricette
。
我该怎么做才能在 html <'ul><'li><'/li><'/ul> 中打印对象?
解决方案
您可以添加父 div*ngFor
以显示数组的所有值,如下所示:
<div *ngFor="let ricetta of ricettaArray">
<h2>{{ricetta.nome}}:</h2>
<div>
<span>Nome-> </span>{{ricetta.nome}}</div>
<ul *ngIf="ricetta?.azioni && ricetta?.azioni.length > 0">
<li *ngFor="let item of ricetta?.azioni ; let i = index" [attr.data-index]="i">
{{item?.tempo}}
{{item?.azione}}
</li>
</ul>
</div>
ricettaArray 声明如下所示:
ricettaArray : Ricette[] = [];
let r1 = {
nome: 'Alici',
azioni: [
{tempo: 500, azione: 'scongela'},
{tempo: 60, azione: 'nulla'}]
};
let r2 = {
nome: 'Blici',
azioni: [
{tempo: 400, azione: 'bcongela'},
{tempo: 50, azione: 'bulla'},
{tempo: 500, azione: 'bulldsfa'}]
};
this.ricettaArray.push(r1);
this.ricettaArray.push(r2);
推荐阅读
- prometheus - Grafana Windows Exporter Dashboard CPU 负载图高达 2.0
- r - 遍历数据中的日期
- python - 如何使用谷歌分析 python API 获取分页记录
- c - 教程点的“C 模拟测试”是否正确?
- bash - 使用 bash 脚本从 ping 中检测操作系统?
- reactjs - 为什么我不能在 React Native 中使用导出默认临时数据
- android - 通过 GmailApi 发送电子邮件时如何修复错误 400
- sharepoint-online - Microsoft Graph - 向 SharePoint Online 中的现有列添加列索引
- c# - 客户端断开连接后,如何让 TCP Server 等待新的客户端连接?
- grafana - 我们可以在 Grafana 中创建仪表板以从 Azure 应用程序网关获取 WAF 日志吗?