我对代码中的一个“愚蠢”部分有问题,对我来说,它应该正常工作,但我不明白它为什么会给我带来问题:
控制器
Ext.define('FedertrekDesktop.controller.Taskbar', {
extend: 'Ext.app.Controller',
views: [
'taskbar.Toolbar',
//'taskbar.Button'
],
showWindow: function(windowName, image, title) {
//var btn = Ext.create('FedertrekDesktop.view.taskbar.Button', windowName, image, title);
//this.getView('taskbar.Toolbar').insert(0, btn);
console.log("tmp: "+this.getView('taskbar.Toolbar').printMsg());
//console.log('msg: '+this.getView('taskbar.Toolbar').getName());
console.log('Create window '+windowName+' '+image);
}
});视图
Ext.define('FedertrekDesktop.view.taskbar.Toolbar', {
extend: 'Ext.toolbar.Toolbar',
alias : 'widget.taskbartoolbar',
items: [
{
xtype: 'tbfill'
},
{
xtype: 'tbseparator'
},
{
xtype: 'button',
enableToggle: true,
text: 'Tasks'
}
],
printMsg: function() {
console.log("printmsg");
}
});实际上,我只是尝试调用自定义函数(printMsg)来进行测试。然而,似乎这个函数缺失了,我真的不明白为什么。我在这里错过了什么?
ERROR:this.getView("taskbar.Toolbar").printMsg不是函数
任何建议都值得赞赏
发布于 2011-12-22 00:21:22
我用参考文献自己解决了这个问题。
结果代码是这样的:
Ext.define('FedertrekDesktop.controller.Taskbar', {
extend: 'Ext.app.Controller',
views: [
'taskbar.Toolbar',
'taskbar.Button'
],
refs: [
{
ref: 'taskbarView',
selector: 'taskbartoolbar'
}
],
showWindow: function(windowName, image, title) {
//var btn = Ext.create('FedertrekDesktop.view.taskbar.Button', windowName, image, title);
//var btn = Ext.create('Ext.button.Button', { text: "Bla" });
//this.getView('taskbar.Toolbar').insert(0, btn);
//var tmp = this.getView('taskbar.Toolbar').create();
//tmp.add(btn);
var tmp = this.getTaskbarView();
tmp.printMsg();
//console.log('msg: '+this.getView('taskbar.Toolbar').getName());
console.log('Create window '+windowName+' '+image);
}
});据我理解,ExtJS并不像我想的那样在控制器中创建对视图的引用,您必须指定它们!
它们提供了参考文献的强大特性,这些特性在控制器和ComponentQuery上都有记录。
在使用它们之后,我对我的代码感到满意。我发布的那篇文章只是一个例子,但从那时起,通过使用insert方法有效地向视图添加一些内容并不困难。
发布于 2011-12-21 03:58:28
this.getView('taskbar.Toolbar').create().printMsg()这行得通吗?根据文档,getView(String name)返回Ext.Base,它没有printMsg函数。
https://stackoverflow.com/questions/8584373
复制相似问题