gpt4 book ai didi

callback - 带有参数的 Ionic2 navController pop(回调)

转载 作者:行者123 更新时间:2023-12-04 13:01:36 25 4
gpt4 key购买 nike

我想在两个页面之间进行回调。
在第 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com