【问题标题】:Ionic 3 : how to parse data from pushed arrayIonic 3:如何解析推送数组中的数据
【发布时间】:2023-04-03 22:11:02
【问题描述】:

好的,所以我按照教程介绍了如何接收 JSON 回复并将它们放入 Ionic 上的 [] 中,我成功地做到了。我将响应存储到 this.infoList 中(在类 'infoList = []' 中声明),当控制台记录它时,它看起来所有数据如下(抱歉隐藏了数据,但用于说明):

https://i.stack.imgur.com/o5JsA.png

我用来推送它的代码是: this.navCtrl.push(ResultPage,this.infoList);

我在 result.ts 的构造函数中尝试记录其中一个详细信息(例如 id)的代码是: console.log(navParams.get('id'));

但它总是首先出现在控制台上并显示为未定义,请指出正确的方向

【问题讨论】:

    标签: angular typescript ionic2 ionic3


    【解决方案1】:

    this.infoLlist 似乎是一个数组。

    选项 1 - 将数组中的第一项作为导航参数传递:

    this.navCtrl.push(ResultPage,this.infoList[0]);
    // then you should be able to do this in the constructor
    console.log(navParams.get('id'));
    

    选项 2 - 通过将整个数组包装在对象字面量中,将其作为导航参数传递:

    this.navCtrl.push(ResultPage,{infoList: this.infoList});
    //then you should be able to do this in the constructor
    console.log(navParams.get('infoList')[0].id);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-05
      • 2018-09-25
      • 1970-01-01
      • 1970-01-01
      • 2018-01-21
      • 1970-01-01
      • 1970-01-01
      • 2018-07-25
      相关资源
      最近更新 更多