Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ExtJs4中的单例_Extjs_Singleton_Extjs4 - Fatal编程技术网

ExtJs4中的单例

ExtJs4中的单例,extjs,singleton,extjs4,Extjs,Singleton,Extjs4,我想在ExtJS4中创建一个单例对象 这是我的密码: Ext.define('AM.model.Test', { extend : 'Ext.util.Observable', singleton : true, foo : function() { console.log('log 1'); }, constructor : function() { } }); 我称之为: AM.model.Test.foo(); 只要我把

我想在ExtJS4中创建一个单例对象

这是我的密码:

Ext.define('AM.model.Test', {
    extend : 'Ext.util.Observable',
    singleton : true,
    foo : function() {
        console.log('log 1');
    },
    constructor : function() {

    }
});
我称之为:

AM.model.Test.foo();
只要我把define放在app.js中,一切都很好。 当我尝试将此定义移动到“app\model\Test.js”时,出现以下错误:

AM.model.Test未定义[在此错误时中断]

AM.model.Test.foo()


我的代码出了什么问题?

您需要设置动态加载,并需要使用它的类

例如:

Ext.Loader.setConfig({
    enabled: true,
    paths: {
        'AM': 'app'
    }
});

Ext.require('AM.model.Test');

Ext.onReady(function() {
    // now all the required classes are loaded and you can start using them
    AM.model.Test.foo();
});