【发布时间】:2014-01-15 03:30:57
【问题描述】:
使用 Sencha Touch,我在其构造函数中定义了一个带有 Ajax 调用的单例类。当我的应用程序启动时,我收到错误消息:Cannot call method 'request' of undefined 从带有“Ext.Ajax.request”的行中调用。
如果我在构造函数中删除 Ajax 调用,我的应用程序将加载而不会出现任何错误。
然后,如果我在我的应用程序启动后调用的另一个函数中进行 Ajax 调用,它就可以工作。所以我假设调用构造函数时 Ext.Ajax 尚未加载。我尝试将 uses 参数添加到我的类,但它不起作用。
Ext.define('MyApp.utils.PostalCode', {
singleton: true,
config : {
postalCodesHashMap : null,
},
uses : 'Ext.Ajax',
constructor: function(config) {
this.initConfig(config);
Ext.Ajax.request({
//will not work
});
},
loadData : function() {
Ext.Ajax.request({
//will work
});
}
});
【问题讨论】:
-
@jprofitt :它有效,谢谢!你可以做一个答案,我会选择它作为正确答案。
标签: ajax extjs constructor singleton sencha-touch-2