这是我的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"]
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);
}
}