我在准备部署应用程序时遇到问题。我正在使用ext-dev.js并拥有以下内容:
Ext.define(myNameSpace.myComponentName, {
requires: ['Ext.XTemplate'],
tpl: new Ext.XTemplate('someTemplate')
})
在应用程序启动时,它会给出一个
Ext.XTemplate不是构造函数
你有解决方案吗?
答案 0 :(得分:2)
您无法定义内联的Ext.XTemplate,因为Ext.Loader尚未从服务器检索它,它处理依赖项的加载。有两种解决方案:
// If you really want to add it to the prototype, but adding objects to the
// prototype is usually a bad idea since they are shared by all instances
// In this case, it may be ok, since there isn't much you can change about a
// template after you create it
Ext.define('myNameSpace.myComponentName', {
requires: ['Ext.XTemplate'],
}, function() {
// This callback is for when all the dependencies are loaded
myNameSpace.myComponentName.prototype.tpl = new Ext.XTemplate('someTemplate')
});
// Or just define it in initComponent, since you shouldn't instantiate it
// until after Ext.onReady is called (which means all dependencies are loaded)
Ext.define('myNameSpace.myComponentName', {
requires: ['Ext.XTemplate'],
initComponent: function() {
this.tpl = new Ext.XTemplate('someTemplate');
this.callParent();
}
});
更新我实际上忘了列出另一种可行的可能性,即不要使用new
,请使用Ext.create('Ext.XTemplate', args)'
。 Ext.create
的问题是它会阻塞,直到加载Ext.XTemplate
(和依赖项)。我仍然会选择顶部提到的两种方法之一