【发布时间】:2018-05-06 08:49:12
【问题描述】:
我正在努力从嵌套在 json 文件中的对象中的数组中检索对象。
Json 文件是这样的:
{
"success": {
"total": 1
},
"contents": {
"quotes": [
{
"quote": "You can’t succeed coming to the potluck with only a fork.",
"author": "Dave Liniger",
"length": "64",
"tags": [
"inspire",
"team-building",
"tso-funny",
"working-with-people"
],
"category": "inspire",
"title": "Inspiring Quote of the day",
"date": "2018-05-05",
"id": null
}
],
"copyright": "2017-19 theysaidso.com"
}
}
我正在尝试检索嵌套在引号中的引号。
到目前为止,我一直在尝试这个:
<ion-list>
<ion-item *ngFor="let c of contents"></ion-item>
<ion-item *ngFor="let q of c['quotes']">
<h2>{{ q.quote }}</h2>
</ion-item>
但是我不断收到“无法获取未定义或空引用的'引号'的属性”
我做错了什么?
【问题讨论】:
-
使用ngFor不能直接访问json文件的内容
-
什么意思?
-
我确实有访问权限。我正在使用提供商 'quote.ts' 。这会将 json 的内容返回给我
-
您正试图访问 ngFor 范围之外的 c
{{ q.quote }}
-
那么如何访问“contents”中的数组“quotes”?
标签: json ionic-framework nested ngfor