angular - ngFor 的离子 GET 对象索引
问题描述
我有以下 JSON 数据。我能够在 js 文件中提取它,并且能够通过 console.log 进行登录。但是,我无法正确显示数据。
我试图在 stackoverflow 上进行搜索,但找不到正确的选项并想寻求帮助。
{
"service": "weather",
"daily": {
"summary": "Light rain tomorrow and Friday.",
"icon": "rain",
"data": [
{
"time": 1581436800,
"summary": "Humid and partly cloudy throughout the day."
},
{
"time": 1581523200,
"summary": "Light rain in the morning and afternoon."
},
{
"time": 1581609600,
"summary": "Possible drizzle in the morning."
},
{
"time": 1581696000,
"summary": "Humid and partly cloudy throughout the day."
},
{
"time": 1581782400,
"summary": "Humid throughout the day."
},
{
"time": 1581868800,
"summary": "Humid and partly cloudy throughout the day."
},
{
"time": 1581955200,
"summary": "Humid and partly cloudy throughout the day."
},
{
"time": 1582041600,
"summary": "Humid throughout the day."
}
]
}
}
带有两个文件供检索和显示。
天气.page.ts
constructor(private http: HTTP) {
this.http.get('http://localhost:8080/weather', {}, {})
.then(data => {
const parsedBody = JSON.parse(data.data)
this.dailyData = parsedBody.daily.data
console.log("this.dailyData:");
console.log(this.dailyData);
})
.catch(error => {
// ...
});
}
天气.page.html
<ion-item *ngFor="let data of dailyData">
<ion-label>
<h2>Tomorrow</h2>
<p>{{data[0].summary}}</p>
</ion-label>
</ion-item>
{{数据[0].summary}}
解决方案
在 *ngFor 中使用异步管道
<ion-item *ngFor="let data of dailyData |async ">
<ion-label>
<h2>Tomorrow</h2>
<p>{{data[0].summary}}</p>
</ion-label>
</ion-item>
推荐阅读
- git - 使用“git rebase to”合并两个功能分支?
- azure-devops - 运行控制台应用程序作为输出测试结果的构建任务
- javascript - Laravel - 搜索时的 Ajax 重复数据
- python - 我们如何使用python中的变量从mysql数据库中获取特定行的详细信息
- javascript - 增加自定义对象的点击次数
- php - SessionHandlerInterface::write 和 SessionUpdateTimestampHandlerInterface::updateTimestamp 有什么区别?
- react-native - 如何使用带有参数的scrollTo函数是ListView中的目标而不是x和y?
- c# - wpf中的数据绑定与getter中的表达式
- javascript - RegExp 仅与路径匹配包含文件名
- angular - 在 ionic 上打开推送通知时必须查看