如何获取列表数据值Ionic 2来自JSON?

时间:2017-11-08 08:28:29

标签: json typescript charts ionic2 ionic3

这是我的JSON数据:

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

这是我的打字稿

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);
    }); 
});

如何在HTML ionic 2中获取这样的Json视图数据?

["100","300","400"]

1 个答案:

答案 0 :(得分:0)

PFB示例代码从数组中提取值并将其放入另一个数组

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);
  }

}