ExtJs4中的单例
我想在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(); 只要我把
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();
});