我想在两个页面之间进行回调。
在第 1 页中,我有以下代码:
DataInfo= [
{
Price: 0,
ClosePrice: 0,
UpdateTime:"",
DefaultPrice:0
}
]
GetClosePrice(i):number{
return DataInfo[i].ClosePrice;
}
我想从第 2 页获取 'i' 的值,当导航 Controller 返回第 1 页时如何加载函数 GetClosePrice() (this.navCtrl.pop())
最佳答案
SOURCE PAGE CLASS
this.navCtrl.push(Page,
{
data: this.data,
callback: this.getData
});
getData = data =>
{
return new Promise((resolve, reject) => {
for (let order of orders) {
this.data = data;
}
resolve();
});
};
TARGET PAGE CLASS
constructor(public navCtrl: NavController, public navParams: NavParams)
{
this.callback = this.navParams.get('callback');
this.data = this.navParams.get('data') || [];
}
sendData(event: any): void
{
this.callback(this.data).then( () => { this.navCtrl.pop() });
}
TARGET PAGE TEMPLATE
<button ion-button (click)="sendData($event)">
关于callback - 带有参数的 Ionic2 navController pop(回调),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42318870/