我在准备部署应用程序时遇到问题。我正在使用 ext-dev.js 并具有以下组件:
Ext.define(myNameSpace.myComponentName, {
requires: ['Ext.XTemplate'],
tpl: new Ext.XTemplate('someTemplate')
})
在应用程序启动时它给出一个
Ext.XTemplate is not a constructor
你有解决办法吗?
最佳答案
您不能内联定义 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();
}
});
UPDATE 其实我忘了列出另一种可能可行的方法,即不要使用 new
,使用 Ext.create('Ext.XTemplate ', 参数)'
。 Ext.create
的问题是它将阻塞,直到加载 Ext.XTemplate
(和依赖项)。我仍然会选择顶部提到的两种方法之一
关于javascript - Ext.Template 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7984174/