typescript - Ionic 3如何接收从一页到另一页的数组
问题描述
我需要将数组从一个页面传递到另一个页面。在第一页中,数组是通过从列表中选择项目来创建的,它会推送所有项目,但是当我在另一个页面中收到这个数组时,它变成了一个数组对象,我无法读取我的 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 中收到时)
提前感谢您的任何想法!
解决方案
您传递的数组在对象 this.datos 的值键处可用
因此,您需要像 this.datos.value 一样阅读它,这应该可以。
谢谢
推荐阅读
- c# - 赛马林。Datagrid 显示在调试模式下工作,但在发布模式下不工作
- c# - 使用 2 个不同的 sdk + 框架编译 c# 项目
- python - 将嵌套字典转换为多列索引数据框
- r - 如何循环第三个变量?
- reactjs - 如何处理 React 中的可重用组件?
- c# - 使用 Roslyn c# 替换 HasOptional()
- gnu-screen - 如何将 GNU 屏幕中的窗口标题设置为当前机器的主机名?
- pcre - 安装 lede-mptcp 时如何解决此 pcre3 错误?
- javascript - 使用javascript搜索锚标题属性
- html - 如何管理月份和年份的下拉菜单?