如何通过Sencha Touch 2控制器中的itemId引用容器的子项?例如,一个xtype为'mypanel'的容器,它包含一个带有itemId'mybutton'的按钮。在控制器中,我想为按钮分配一个偶数处理程序。我该怎么做?
我的应用非常庞大且经常有一个组件的重复,因此我不会在我的应用中的任何位置使用ID,而是使用itemId。
Ext.define('myapp.controller.Test', {
extend: 'Ext.app.Controller',
config: {
control: {
myButton: {
tap: 'showView'
}
},
refs: {
myPanel: 'mypanel',
myButton: '?'
}
},
showView: function(){
}
});
答案 0 :(得分:3)
refs: {
mybutton: 'mypanel #mybutton'
}
有关ComponentQuery的更多信息,请访问:http://docs.sencha.com/touch/2-0/#!/api/Ext.ComponentQuery
答案 1 :(得分:0)
使用 itemId 而不是 id 时,您还需要在控制器的ref中提及包含itemId的元素,如下所示:
refs: {
mybutton: 'xtype_of_panel #itemId_button'
//where 'itemId_button' is the itemId and 'xtype_of_panel' is the parent that contains the element with the itemId of 'itemId_button'
}