【问题标题】:TypeError: Object #<Object> has no methodTypeError: Object #<Object> 没有方法
【发布时间】:2014-07-07 12:11:19
【问题描述】:

我正在使用 Worklight Ibm 开发一个混合应用程序,将 sencha touh 用于 UI。

在我的控制器中,我像这样调用 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());
},

无需调用适配器即可工作。

你能帮帮我吗!

谢谢

【问题讨论】:

    标签: sencha-touch ibm-mobilefirst worklight-adapters


    【解决方案1】:

    尝试执行以下操作:

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

    其中 callbackFunction 是您上面的回调。我认为问题在于回调上下文中未指定变量“this”,因此通过使用apply,您指定“this”应该是您指定的值。试试看它是否有效,虽然我不确定它是否能解决你的问题,因为我不知道它是否会在回调函数中使用给定的“this”。

    【讨论】:

    • 感谢您的回答。实际上问题出在“这个”上。我做了这样的声明: var me = this;然后在我需要的时候使用我,它可以工作
    猜你喜欢
    • 1970-01-01
    • 2016-01-03
    • 2015-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多