Sencha Touch controller、model、store动态注册

动态加载的优势:提升应用启动的速度,之前都放在app.js注册,app会把所有注册的都实例化,导致启动很慢,经过测试应用开始加载时间明显缩短

Controller和Store层
// 判断是否创建过实例
if(!Ext.ClassManager.isCreated("Test.controller.phone.app0050000007.app0050000007Controller")){
// 加载controller, view, model, store JS文件
Ext.require(["Test.controller.phone.app0050000007.app0050000007Controller","Test.store.app0050000007.app0050000007Store"], function(){
//创建controller实例并绑定到application
// Sencha 2.2使用app.js中注册的Application Name作为全局命名空间,属性app保存application的实例
Ext.create("Test.controller.phone.app0050000007.app0050000007Controller", {
			application: Test.app
});
Ext.create("Test.store.app0050000007.app0050000007Store", {
			application: Test.app
    	});

});
}

Model层的动态加载放在store层管理如下所示:
Ext.define("Test.store.app0050000007.app0050000007Store", {
           extend: "Ext.data.Store",
           requires: 'Test.model.app0050000007.***, 
           autoLoad:true,
           config: {
        	   model : 'Test.model.app0050000007.***,
        	   storeId : app0050000007Store,
           }
});

注:1、requires必须引入 2:storeId必须加入,动态加载store是根据storeId获取,命名方式可以和上面定义的类名相同。

你可能感兴趣的:(Sencha Touch)