【问题标题】:How to get list data value Ionic 2 From JSON?如何从 JSON 获取列表数据值 Ionic 2?
【发布时间】:2018-04-20 20:25:44
【问题描述】:

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

【问题讨论】:

  • var totalArray = data.map((item) => item.total);
  • 成功了!!!!,非常感谢

标签: json typescript charts ionic2 ionic3


【解决方案1】:

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

}

【讨论】:

    猜你喜欢
    • 2017-03-08
    • 1970-01-01
    • 1970-01-01
    • 2019-01-15
    • 2016-10-24
    • 2021-11-28
    • 1970-01-01
    • 2017-04-05
    • 1970-01-01
    相关资源
    最近更新 更多