2015-01-20 53 views
0

目前在我的Web應用程序中,我正在執行如下面的代碼所示。 因此,在達到$ window後,會發生什麼情況.Confirm編譯器會等待警報框的響應,並取決於請假得到true或false。 最後,此方法將該布爾值返回至其耦合方法。如何使用HYBRID mobileApp(iOS)中的notification.confirm替換window.confirm

// **的Web APP ** //

function shouldLeave(next) 
       var message = 'Do you wish to leave this Page'; 
       var leave = $window.confirm(message); // Return bool value as per user selection 

       if (leave) { 
        //Doing my job... 
        reset(); 
       } 
       return leave; 
      } 

現在雜交我在做什麼是:

function shouldLeave(next) { 
       var message = 'Do you wish to leave this Page'; 
       var leave = notification.confirm(message, callbackMethod(),title,[Ok, Cancel]); // Here there is no return value . Return depends on Callback as the callback method gets called depending on user selection 

       if (leave) { 
        //Doing my job... 
        reset(); 
       } 
       return leave; 
      } 

function CallBack(index) 
{ 
switch(index) 
{ 
case 1 : 
leave=true; break; 
case 2 : 
leave=false; break; 
default: 
leave=-1; break 
} 
return leave; 

} 

執行Notification.confirm經過編譯所以在這裏不等待用戶響應並轉到下一行(但對於Window,確認是這樣做的)。 所以現在我的疑問是如何重構這段代碼,以便mu離開方法將返回適當的離開值到它的耦合方法。因爲在我的回調方法執行混合應用程序中的用戶交互後shouldLeave完成其執行。所以它不像$ window.confirm功能。

任何建議表示讚賞。

回答

0

入住這

function shouldLeave() { 
     var message = 'Do you wish to leave this Page'; 
     navigator.notification.confirm(
      message, // message 
      onConfirm,      // callback to invoke with index of button 
      'Confirmation',     // title 
      'Ok, Cancel'     // buttonLabels 
     ); 
    } 


    //on button press, the onConfirm function is called 
    function onConfirm(button) { 
     //console.log('You selected button ' + button); 
     if(button == 1){ 
      //pressed "Ok" 
      console.log("Ok ACTION"); 
     } 
     else if(button == 2){ 
      //pressed "Cancel" 
      console.log("Cancel ACTION"); 
     } 
    } 

這應該工作。

+0

謝謝伊姆蘭。我知道這種方法,但我的要求是不同的。聽起來像我需要重構我的代碼。 – Baidyanath 2015-01-21 15:57:11

0

變化

notification.confirm(message, callbackMethod(), title, [Ok, Cancel]); 

notification.confirm(message, callbackMethod, title, [Ok, Cancel]); 

說明: 如果你把callbackMethod(),則一旦執行的執行到達該行 如果你把callbackMethod withouth的了(),你宣佈要在回調中執行的功能。

+0

但我的要求是編譯器應該停止@ notification.confirm,直到執行回調方法。就像在window.confirm方法中發生一樣。但在這裏我的編譯器正在轉向下一步。 – Baidyanath 2015-01-21 14:31:13

+0

那麼這是不可能的,你想要執行回調時執行的代碼必須在該回調中 – jcesarmobile 2015-01-21 14:54:55

相關問題