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

标签 callback ionic2

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

相关文章:

javascript - 使javascript函数回调-ish

Scala Future 回调 hell

angular - 将数据传递到 ionic2 菜单

objective-c - 我是否必须在 objective-c 的 .h 文件中声明回调方法?

javascript - 在 native Node 的回调中调用回调

angular - Ionic App,Typescript 错误找不到名称 'RequestMode'

javascript - 如何验证 Ionic 中动态添加的 ionic 输入

ionic-framework - ionic 2 : View does not update based on model change

css - 自定义图标选项卡 Ionic 3

objective-c - 将 Objective-C 与 C 和代码组织混合