Ionic 中的嵌套 JSON 数据
Nested JSON Data in Ionic
在此先感谢,我正在将 Ionic 4 用于移动应用程序,并且在页面上需要列出嵌套数据,但我似乎无法正确处理。
以下是JSON数据
"campaign_performance": {
"id": 11783,
"name": "calvinseng.com",
"mobile": "false",
"date_from": "2018-01-01",
"date_to": "2018-01-02",
"keywords": [
{
"id": 235505,
"name": "hot stamping printing",
"positions": {
"2018-01-01": 1,
"2018-01-02": 1
}
},
{
"id": 235506,
"name": "creative agency singapore",
"positions": {
"2018-01-01": 59,
"2018-01-02": 57
}
}
]
}
在页面上,我所做的 html 是
<ion-list color="primary" *ngFor="let campaign of userService.campaign_performance">
{{ campaign.name }}
<ng-container *ngFor="let keyword of userService.campaign_performance.keywords">
{{ keyword.id }}
</ng-container>
</ion-list>
但是 html 在视图中没有返回任何内容。
希望实现与附件类似的东西。任何的想法?
这看起来更有可能是:
<ion-list color="primary" *ngFor="let campaign of userService.campaign_performance">
{{ campaign.name }}
<ng-container *ngFor="let keyword of campaign.keywords">
{{ keyword.id }}
</ng-container>
</ion-list>
您正在循环每个 campaign_performance
并将其分配给 campaign
。
因此,如果您想进行内部循环,那么您可以从该变量开始并循环其各个内容。
在此先感谢,我正在将 Ionic 4 用于移动应用程序,并且在页面上需要列出嵌套数据,但我似乎无法正确处理。
以下是JSON数据
"campaign_performance": {
"id": 11783,
"name": "calvinseng.com",
"mobile": "false",
"date_from": "2018-01-01",
"date_to": "2018-01-02",
"keywords": [
{
"id": 235505,
"name": "hot stamping printing",
"positions": {
"2018-01-01": 1,
"2018-01-02": 1
}
},
{
"id": 235506,
"name": "creative agency singapore",
"positions": {
"2018-01-01": 59,
"2018-01-02": 57
}
}
]
}
在页面上,我所做的 html 是
<ion-list color="primary" *ngFor="let campaign of userService.campaign_performance">
{{ campaign.name }}
<ng-container *ngFor="let keyword of userService.campaign_performance.keywords">
{{ keyword.id }}
</ng-container>
</ion-list>
但是 html 在视图中没有返回任何内容。
希望实现与附件类似的东西。任何的想法?
这看起来更有可能是:
<ion-list color="primary" *ngFor="let campaign of userService.campaign_performance">
{{ campaign.name }}
<ng-container *ngFor="let keyword of campaign.keywords">
{{ keyword.id }}
</ng-container>
</ion-list>
您正在循环每个 campaign_performance
并将其分配给 campaign
。
因此,如果您想进行内部循环,那么您可以从该变量开始并循环其各个内容。