2017-11-08 1 views
0

Diese meine JSON-Daten:So erhalten Sie Listendatenwert Ionic 2 von JSON?

[ 
    { 
    "id": 1, 
    "label": "saw", 
    "total": "100" 
    }, 
    { 
    "id": 2, 
    "label": "saw1", 
    "total": "300" 
    }, 
    { 
    "id": 3, 
    "label": "saw2", 
    "total": "400" 
    } 
] 

Das ist mein Typoskript

this.http.get('http://www/upnionic/chart.php') 
    .map(res => res.json()).subscribe(data => { 
    this.qwerty = data; this.qwerty.forEach(element => { 
     let product = element.total; 
     this.pieChartData = product; 
     console.log(product); 
    }); 
}); 

Wie Ansicht Daten Json wie dies in HTML ionischen 2 bekommen?

["100","300","400"] 
+0

'var totalArray data.map = ((item) => item.total);' – devqon

+0

Dies funktionierte !!!!, Danke vielmals –

Antwort

0

PFB Der Beispielcode Wert von Array zu extrahieren und sie in ein anderes Array setzen

import { Component } from '@angular/core'; 
import { NavController } from 'ionic-angular'; 

@Component({ 
    selector: 'page-home', 
    templateUrl: 'home.html' 
}) 
export class HomePage { 
    jsonData : any; 
    val : any=[]; 
    constructor(public navCtrl: NavController) { 
    this.jsonData=[{"id":1,"label":"saw","total":"100"},{"id":2,"label":"saw1","total":"300"},{"id":3,"label":"saw2","total":"400"}]; 
    this.jsonData.map((item)=>{ 
     this.val.push(item.total); 
    }); 
    alert(this.val); 
    } 

} 
Verwandte Themen