[英]How to access json object in Ionic / Angular
我需要在這個json中訪問firstBill
值:
[{
"companyName": "Madrid",
"producCompanyId": 4,
"productCompanyName": "Empresa1",
"state": {
"id": 5,
"description": "Completada sin precios"
},
"message": "\nHay otra empresa igual en ACTIVO "
}, {
"companyName": "Barcelona",
"producCompanyId": 10,
"productCompanyName": "Empresa2",
"companyResultId": "889",
"state": {
"id": 4,
"description": "Completada con precios"
},
"prices": {
"priceList": [{
"priceId": 699614,
"companyPriceId": "1091931204",
"firstBill": 281.96,
"issuable": true
}, {
"priceId": 699609,
"companyPriceId": "1091931204",
"firstBill": 251.64,
"issuable": true
}, {
"priceId": 699611,
"companyPriceId": "1091931204",
"firstBill": 302.6,
"issuable": true
}]
},
"message": ""
}]
現在我有這個代碼,但是由於未定義的prices
jsonarray在其他(前面的json中的第一個)對象中有錯誤:
<ion-content class="home">
<ion-list>
<ion-item *ngFor="let oferta of ofertas">
<h2>{{oferta.companyName}}</h2>
<pre>{{ oferta.prices.priceList[0] ? oferta.prices.priceList[0] | json }}</pre>
</ion-item>
</ion-list>
</ion-content>
嘗試下面的修改代碼。 可能這可以幫到你。 我添加了一些嵌套div結構的ngIf。
<ion-list>
<ion-item *ngFor="#oferta of ofertas">
<h2>{{oferta.companyName}}</h2>
<div *ngIf="oferta.prices">
<div *ngFor="#plist of oferta.prices.priceList">
<pre>{{ plist | json }}</pre>
</div>
</div>
</ion-item>
</ion-list>
this.ofertas = [{
"companyName": "Madrid",
"producCompanyId": 4,
"productCompanyName": "Empresa1",
"state": {
"id": 5,
"description": "Completada sin precios"
},
"message": "\nHay otra empresa igual en ACTIVO "
}, {
"companyName": "Barcelona",
"producCompanyId": 10,
"productCompanyName": "Empresa2",
"companyResultId": "889",
"state": {
"id": 4,
"description": "Completada con precios"
},
"prices": {
"priceList": [{
"priceId": 699614,
"companyPriceId": "1091931204",
"firstBill": 281.96,
"issuable": true
}, {
"priceId": 699609,
"companyPriceId": "1091931204",
"firstBill": 251.64,
"issuable": true
}, {
"priceId": 699611,
"companyPriceId": "1091931204",
"firstBill": 302.6,
"issuable": true
}]
},
"message": ""
}]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.