2014-07-07 80 views
0

我正在開發與Worklight Ibm混合應用程序,使用sencha touh進行UI。TypeError:對象#<Object>沒有方法

在我的控制器

我打電話的HTTPAdapter這樣的:

var invocationData = { 
    adapter : 'UserHttpAdapter', 
    procedure : 'getPersonneMorale', 
    parameters : [] 
}; 

WL.Client.invokeProcedure(invocationData, { 
    onSuccess : function() { 
     console.log('Signed in.'); 
     var loginView = this.getLoginView(); 
     mainMenuView = this.getMainMenuView(); 
     loginView.setMasked(false); 

     Ext.Viewport.animateActiveItem(mainMenuView, this 
       .getSlideLeftTransition()); 
    }, 
    onFailure : function(){ 
     console.log('failure'); 
    }, 
}); 

但我得到這個錯誤:

07-07 11:43:45.812: E/NONE(31172): [http://<domain>:<port>/WLErsalMobileTest/apps/services/api/ErsalMobileTest/android/query] exception. TypeError: Object #<Object> has no method 'getLoginView' 
07-07 11:43:45.832: D/CordovaLog(31172): file:///android_asset/www/default/worklight/worklight.js: Line 3333 : Uncaught TypeError: Object #<Object> has no method 'getLoginView' 
07-07 11:43:45.832: E/Web Console(31172): Uncaught TypeError: Object #<Object> has no method 'getLoginView':3333 

,當我執行的代碼:

signInSuccess : function() { 
    console.log('Signed in.'); 
    var loginView = this.getLoginView(); 
    mainMenuView = this.getMainMenuView(); 
    loginView.setMasked(false); 

    Ext.Viewport.animateActiveItem(mainMenuView, this.getSlideLeftTransition()); 
}, 

沒有調用它適用的適配器。

你能幫助我嗎!

謝謝

回答

0

試着做以下幾點:

WL.Client.invokeProcedure.apply(this, [invocationData, callbackFunction]) 

其中callbackFunction參數是你有以上的回調。我認爲問題是變量'this'沒有在回調上下文中指定,所以通過使用apply,你指定'this'應該是你指定的值。試試看看它是否有效,但我不確定它是否能解決您的問題,因爲我不知道它是否會在回調函數中使用給定的'this'。

+1

謝謝你的回答。其實這個問題與'this'有關。我做了這樣的聲明:var me = this;然後在我需要的時候使用我,並且它可以工作 –

相關問題