javascript - Ext.Template 未定义

标签 javascript extjs

我在准备部署应用程序时遇到问题。我正在使用 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/

相关文章:

javascript - 如果我在浏览器列表中组合未死有什么区别?

javascript - 将所有文本链接转换为实际链接

javascript - 选择选项值时如何引用页面?

Extjs 4 : how to change progressbar colour dynamically?

extjs - 带图标的树形列渲染器 - extjs 4.2.1

javascript - ExtJS::如何过滤网格中的行,但不过滤存储中的行

javascript - 在 PHP 和 Ajax 中使用 Json 传递值

javascript - 获取字符串的一部分?

json - EXT Js 复杂 JSON 响应处理 : Grid Insertion

javascript - ExtJS提交表单下载文件