2017-09-05 13 views
0

Hallo Leute, das ist vielleicht eine dumme Frage, aber ich bin neu für die ionische Entwicklung, sehe Probleme beim Anzeigen von Werten aus jsonobject, jetzt lass mich detailliert erklären, dass ich jsonobject vom Webservice geholt habe und es anzeigen muss und ich den Wert erfolgreich abgerufen habe von Service, aber konnte es nicht während angezeigt werden können, bin ich versucht bekommen kann nicht bereit Eigenschaft ‚StatusName‘ undefined mich jetzt schreiben lassen, was ich bisher versucht haben:Fehler beim Versuch, Wert von Jsonobject in ionic 3 anzuzeigen?

Das ist mein json aus dem Dienst bekommen:

{ 
    "StatusName": "Open", 
    "ApprovalStatusName": "Awaiting Approval", 
    "CreatedByName": "Mark (Marx)", 
    "LastModifiedByName": "Mark (Marx)", 
    "ContractID": 20, 
    "ContractCode": "PIL", 

} 

Und das ist die Typoskript-Seite:

export class ContractApprovalViewPage { 
    private contracts :any; 
    private contracttype:any; 
    private results:any; 


    constructor(public navCtrl: NavController, public navParams: NavParams,public contractApprovalViewService:ContractApprovalViewService) { 
    this.contracts=this.navParams.get('result'); 
    this.getContractApprovalView(this.contracts); 

} 

getContractApprovalView(contracttype){ 
     this.contractApprovalViewService.getContractApproval(contracttype).then(data => { 
      //console.log(data); 
      this.results=data; 
      console.log(this.results); 
      console.log(this.results.CustomerName); 
     }); 
    } 
} 

Das ist mein Service Seite:

import { Injectable } from '@angular/core'; 
import { Http } from '@angular/http'; 
import { Events } from 'ionic-angular'; 
import 'rxjs/add/operator/map'; 
@Injectable() 
export class ContractApprovalViewService { 

    private _result; 
    constructor(public http: Http, public events: Events) { } 
    getContractApproval(contracttype:any) { 
    return new Promise(resolve => { 
      this.http.get('http://172.16.6.187/sf/api/cnrt/getContractapprovalview/'+ contracttype.Column0 +'/C').subscribe(
       data => { 
       // console.log('http://xxxx/xx/xx/'+ contracttype.Column0 +'/C'); 
        this._result = data; 
        resolve(JSON.parse(this._result._body)); 
       }, 
       err => { 
        this._result = err; 
      //  this.events.publish("message:error", JSON.parse(this._result._body)); 
       } 
      ); 
     }); 
    } 
} 

Das ist meine HTML-Seite:

<ion-header> 

    <ion-navbar> 
    <ion-title>Approval</ion-title> 
    </ion-navbar> 

</ion-header> 


<ion-content > 
<ion-list no-padding> 
    <ion-card> 
    <ion-item > 
    {{results.StatusName}} 
    </ion-item> 
    </ion-card> 
    </ion-list> 
</ion-content> 

Sie wissen nicht, wo Fehler machen, wie jemand mir beibringen, wo falsch ist, Danke voraus!

Antwort

3

Zuerst erklären Variable oben Konstruktor

statusName:string; 

dann in unten Funktion

getContractApprovalView(contracttype){ 
     this.contractApprovalViewService.getContractApproval(contracttype).then(data => { 
      //console.log(data); 
      this.results=data; 
      console.log(this.results); 
      this.statusName = this.results.statusName; 
      //this.results.statusName status name key should match the response you are getting. 
      console.log(this.results.CustomerName); 
     }); 
    } 
} 

jetzt in html nur Statusausdruck Name

wie Sie nicht vorbei Array so Verwendung Ergebnisse nicht. statusname

<ion-content > 
<ion-list no-padding> 
    <ion-card> 
    <ion-item > 
    {{statusName}} 
    </ion-item> 
    </ion-card> 
    </ion-list> 
</ion-content> 
+0

Vielen Dank Ihre Lösung funktioniert. –

Verwandte Themen