Extjs 4.1 Check Change Listener
Вопрос
What is the right way to handle menu check items events ?
I have this menu:
{
xtype: 'button',
id: 'types_btn',
autoWidth: true,
text: 'Types',
menu: {
xtype: 'menu',
frame: true,
id: 'types_menue',
items: [
{
xtype: 'menucheckitem',
id: 'f_type',
text: 'first',
listeners: {
checkchange: {
fn: me.onFirstButtoncheckchange,
scope: me
}
}
},
{
xtype: 'menucheckitem',
id: 's_type',
text: 'second',
listeners: {
checkchange: {
fn: me.onSecondButtoncheckchange,
scope: me
}
}
}
Then the functions:
onFirstButtoncheckchange: function(menucheckitem, checked, options) {
var t = Ext.getCmp('f_type');
if (t.checked)
goToFunction(???);
.
.
},
onSecondButtoncheckchange: function(menucheckitem, checked, options) {
var t = Ext.getCmp('s_type');
if (t.checked)
goToFunction(???);
.
.
},
1- Is there anyway to use one listener and gather all different functions in it ?
2- How can I send the current item to goToFunction() as you see in the code ?
Решение
Just make an handler for each menu check item:
items: [{
xtype: 'menucheckitem',
text: 'select all' ,
id: 'first' ,
listeners: {
checkchange: me.myHandler
}
},{
xtype: 'menucheckitem',
text: 'select specific' ,
id: 'second' ,
listeners: {
checkchange: me.myHandler
}
}]
And your handler defined as follows:
myHandler: function (menucheckitem, checked, opts) {
switch (menucheckitem.getId ()) {
// Here handles the first
case 'first':
if (checked) {
console.log ('First checked!');
goToFunction ();
}
break;
// Here handles the second
case 'second':
if (checked) {
console.log ('Second checked!');
goToFunction ();
}
break;
default:
console.log ('Whatever!');
}
}
Другие советы
Looks like the listener doesn't get triggered quite often. You can use checkHandler config instead.
Не связан с StackOverflow