簡體   English   中英

如果彈出框處於活動狀態,則不會顯示Ionic2警報

[英]Ionic2 Alert does not show if a popover is active

我有一個列表,用戶可以在其中從列表項調用彈出窗口。 在彈出框內,選擇一個選項后,應創建一個確認警報。

問題是當我嘗試在彈出窗口打開時調用警報時,它無法正確顯示。 它似乎在列表的后面,並且列表變得沒有響應(不再接受點擊)...

為了進行測試,建議如果我直接通過單擊項目添加警報,而不是從彈出菜單中選擇的選項,警報將正確顯示。

在創建列表和彈出窗口的頁面上:

public OnItemOptionsPress(event, item)
  {
        event.stopPropagation();

        let popoverOptions =
        [
              { 
                    Resource: "Remove",  
                    Icon: "icon-trash",               
                    Callback: (event, item) => 
                    { 
                          this.confirmRemoveItem(event, item) 
                    },
              }
        ];

        let popover = this.PopoverController.create
        (
              PopoverOptions, 
              { 
                    Owner: item, 
                    Items: this.popoverOptions 
              }
        );

        popover.present({ ev:event });
  }

  public confirmRemoveItem(event, item)
  {
        let alert = this.AlertController.create
        (
              {
                    title: 'Remove Item',
                    message: 'Do you want to remove?',
                    buttons: 
                    [
                          {
                                text: 'No',
                                role: 'cancel',
                                handler: () => 
                                {
                                      console.log('No has been clicked');
                                }
                          },
                          {
                                text: 'Yes',
                                handler: () => 
                                {
                                      console.log('yes has been clicked');

                                      this.removeItem(item);
                                }
                          }
                    ]
              }
        );

        alert.present();
  }

  public removeItem(item)
  {
        this.items.splice(item.Index, 1);
  }

在彈出框內,選擇一個選項並調用close函數時:

  public close(event, item) 
  {
        if (item.Callback) item.Callback(event, this.Owner);

        this.ViewController.dismiss();
  }

我注意到dismiss()方法正在返回諾言。 在關閉彈出窗口並調用回調異步時,我不得不添加一個延遲。

  public close(event, item:PopoverItemModel) 
  {    
        let animation = this.ViewController.dismiss();

        animation.then(()=>
        {
               if (item.Callback) item.Callback(this.Owner);
        });

        //if (item.Callback) item.Callback(this.Owner);
  }

現在可以了...但是有一個奇怪的延遲(彈出窗口完成其動畫並被關閉的時間)。 可能是viewcontroller無法同時處理多個動畫/組件過渡...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM