【问题标题】:Ionic 3 how to receive an array from one page to another pageIonic 3如何接收从一页到另一页的数组
【发布时间】:2020-01-25 02:54:18
【问题描述】:

我需要将数组从一个页面传递到另一个页面。在第一页中,数组是通过从列表中选择项目创建的,它推送所有项目,但是当我在另一个页面中收到这个数组时,它变成了一个数组对象,我无法读取我的 html 页面中的数据,这里是我的部分代码:

labo.ts - 这是我创建数组的方式,而且很好

selectItem(itemKey){
   const foundAt = this.selectedQuestions.indexOf(itemKey);
   if (foundAt >= 0) {
      this.selectedQuestions.splice(foundAt, 1);
   } else {
      this.selectedQuestions.push(itemKey);
   }
  console.log(this.selectedQuestions);

}

添加完项目后,我将其发送到 calendar.ts

calendar(){
 console.log("ARRAY ", this.selectedQuestions)
    this.navCtrl.push(CalendarioPage,{
      queryParams: {
           value : this.selectedQuestions
       },
  });

}

这是calendaar.ts,我需要在这里接收数组:

 export class CalendarioPage {
  datos: Array<object>;

  constructor(public navCtrl: NavController, public navParams: NavParams,
    public http: Http, private conteSearch : ContesearchProvider) {

    this.datos = navParams.get("queryParams");

    console.log("array -> ", this.datos)

  }  
 }

在我的 calendar.html 文件中,我尝试读取数组:

<div *ngFor="let dato of datos">
  {{dato.nombre}} 
</div>

我收到此错误“错误错误:”未捕获(在承诺中):错误:找不到“对象”类型的不同支持对象“[对象对象]”。 NgFor 只支持绑定到 Iterables,比如 Arrays。”

这是数组前后的样子(在 calendar.ts 中收到时)

提前感谢您的任何想法!

【问题讨论】:

    标签: typescript ionic3 angular4-router


    【解决方案1】:

    您传递的数组在对象 this.datos 的 value 键处可用

    所以你需要像this.datos.value一样阅读它,这样应该可以。

    谢谢

    【讨论】:

    • 您好 Tek,它有效,非常感谢。我只是更改了 html :
      {{dato.nombre}}
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    • 2017-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-24
    • 2016-01-23
    相关资源
    最近更新 更多