我正在构建 Sencha touch 2.1 应用程序。
在我的应用程序中,我有一个全局变量,它保持对我的控制器类的引用。此引用用于在加载其中一个商店时执行控制器功能,但是当我将其部署在慢速远程服务器上并在此全局变量获取控制器对象的引用之前触发商店的负载时,问题就来了。为了在存储加载之前提供此参考,我尝试将初始化逻辑放入控制器的 init 方法中
init : function(){
bossController = this.getApplication().getController('Boss');
},
在控制器的 init 方法中,但在调用此 init 之前加载了视图和存储,因此我收到此错误:
Cannot call method 'loadMagazines' of undefined
这是我在商店中的加载监听器:
listeners:{
load: function( me, records, successful, operation, eOpts ){
bossController.loadMagazines(this, records);
}
}
我尝试在 app.js 的 launch() 方法而不是控制器的 init 方法中初始化这个变量,但这也不起作用。
请注意,当我将代码放在本地 apache 中并使用我的 chrome 浏览器访问它时,这两种方法都可以正常工作,但是当我将它放在慢速远程服务器上时它们不起作用。
编辑
这就是应用程序流程发生的方式 0。所有模型、视图、存储和控制器都在 app.js 中定义
app.js 中的启动函数将主视图添加到视口。
主视图创建杂志视图并将其添加到自身。
在杂志视图的初始化方法中,商店被装箱并加载。
在商店的加载监听器中,使用了控制器。
这是我的看法:
Ext.define('myshop.view.MagazinePanel', {
extend : 'Ext.Panel',
requires : [
'myshop.model.MagazinePage',
'myshop.store.MagazineStore',
'Ext.XTemplate',
'Ext.data.Store'
],
alias : 'widget.magazinepanelview',
xtype : 'magazinepanelview',
config : {
layout : 'hbox',
id : 'hc',
scrollable: 'horizontal',
directionLock : true,
masked: {
xtype: 'loadmask',
message: 'Loading'
},
inline: {
wrap: false
},
items : [{
xtype : 'panel',
html : ''
}]
},
initialize: function() {
var me = this;
var myStore = Ext.create('myshop.store.MagazineStore');
myStore.load({
callback: function(records, operation, success) {
me.setMasked(false);
},
scope: this
});
this.callParent();
}
});
这是商店:
Ext.define('myshop.store.MagazineStore',{
extend:'Ext.data.Store',
requires: [
'myshop.model.MagazinePage',
'Ext.data.proxy.JsonP'
],
config:{
storeId : 'ms',
model:'myshop.model.MagazinePage',
autoLoad :false,
pageSize: 30,
proxy : {
type: 'jsonp',
url: Properties.PORTAL_SERVICE_BASE_URL+'test/categories/list',
callbackKey: 'callback',
startParam: false, //to remove param "start" and making it constant
extraParams: {
start : 0,
_type : 'json'
},
reader: {
type: 'json',
rootProperty: 'categories.data',
totalProperty: 'categories.status.totalCount'
}
},
listeners:{
load: function( me, records, successful, operation, eOpts ){
bossController.loadMagazines(this, records);
}
}
}
});