【问题标题】:Ext.application: Uncaught TypeError: undefined is not a functionExt.application: Uncaught TypeError: undefined is not a function
【发布时间】:2015-01-14 06:45:15
【问题描述】:

我的 extjs 5 应用程序有一些问题。我正在使用 Sencha Architect 并在 FreeBSD 上运行该应用程序。

我得到的错误是 Uncaught TypeError: undefined is not a function for 'Ext.application'

这是我的代码

// @require @packageOverrides
Ext.Loader.setConfig({

});


Ext.application({
models: [
    'BassSearch',
    'BassSearchResult',
    'Menu',
    'Customer',
    'Subscription',
    'NetInfo',
    'Products',
    'AddressSearch',
    'AddressAll',
    'Interface',
    'Phone'
],
stores: [
    'SearchStore',
    'CustomerStore',
    'NetinfoStore',
    'InterfaceStore',
    'PhoneStore',
    'BassMenuStore',
    'JsonSubscriptions'
],
views: [
    'fSearch',
    'searchResult',
    'SearchPanel',
    'ApplicationPanel',
    'MenuPanel',
    'MainBass',
    'CustomerInfoView'
],
controllers: [
    'searchController',
    'MenuSubController',
    'CustomerInfoController'
],
name: 'MyApp',

launch: function() {
    Ext.create('MyApp.view.MainBass');
    //load
    var myCookieVal = document.cookie.indexOf('basssessionid');
    if (myCookieVal) {
        window.location.href="index.html";
    } else {
        var xhReq = new XMLHttpRequest();
        var request = 'api/checkSession';
        xhReq.open("GET", request, false);
        xhReq.send(null);
        var json = JSON.parse(xhReq.responseText);
        if (!json.success) {
            window.location.href="index.html";
        }
    }
    Ext.define('BASSSharedData', {cid: 0});

    MyApp.globals = {
        currentcid: 0,
        userid: 0,
        callback: "",
        subscriptionid: 0,
        currentView: null
    };


}

});

任何帮助appriciated。

谢谢

【问题讨论】:

    标签: javascript extjs


    【解决方案1】:

    该错误通常意味着您正在调用尚未初始化的对象的函数(最相似的是 JAVA 中的 NullPointerException)。如果 xhReq.send(null);是异步的或失败,当您在下一条语句中调用它时,xhreq.responseText 应该为 null/undefined。

    阅读本教程以了解如何使用“XMLHTTPRequest”。如果 xhReq.responseText 不是原因,请尝试使用 Chrome 或 Firefox 的 Firebug 调试代码,或者将 'alert()' 放在不同的位置以查看原因的来源。

    【讨论】:

    • 您好 Varun,感谢您的回复。我正在一个测试服务器上开发这个,它使用与我们的生产相同的后端,并且在生产服务器上它工作正常。
    • 你也可以试试 'alert()' 或者 'console.log()'。我也面临客户端与测试/生产服务器的行为差异。但是我的应该是打包成一个移动应用程序,这个问题与跨域请求有关。