我有一个像这样的工具栏
tbar: [{
xtype : 'textfield',
name : 'number',
itemId : 'number',
listeners : {
change : function(t,n){
console.log(this.up('toolbar').down('#splitbut')) // i can access splitbutton from here
}
}
},{
xtype : 'splitbutton',
text : 'Report',
disabled: true,
itemId : 'splitbut',
menu : [{
text : 'details',
handler : function() {
// how to access #number text field from here
}
}
我在菜单按钮处理程序中尝试了this.up('menu')。up('toolbar')但我尝试了每种方式的未定义消息
知道如何从菜单按钮访问#number文本字段吗?
此致
答案 0 :(得分:1)
我会分别定义textfield和splitbutton,然后以这种方式引用它们。
this.myTextField = new Ext.form.field.Text ({
name: 'number',
itemId: 'number',
listeners: {
change: function(t,n){
console.log(this.mySplitButton)
}
}
this.mySplitButton= new Ext.button.Split ({
text: 'Report',
disabled: true,
itemId: 'splitbut',
menu: [{
text: 'details',
handler: function() {
console.log(this.myTextField )
}
}
答案 1 :(得分:0)
Gihan您的菜单项不会从具有up功能的组件扩展。尝试将范围传递给处理函数:
handler: function() {
console.log(this.myTextField )
},
scope: this or this.mySplitButton
在函数内设置断点并在firebug中检查它。你会清楚地看到那个'这个'指的是什么。此外,如果您要在ExtJS中进行开发,我强烈建议您为Firefox的开发人员获取Illuminations - 您一定会喜欢它。