Extjs 4.1检查更改监听器 [英] Extjs 4.1 Check Change Listener
本文介绍了Extjs 4.1检查更改监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
处理菜单检查项事件的正确方法是什么?
What is the right way to handle menu check items events ?
我有这个菜单:
{
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
}
}
}
然后执行功能:
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-无论如何,有没有使用一个监听器并在其中收集所有不同的功能?
1- Is there anyway to use one listener and gather all different functions in it ?
2-如您在代码中看到的,如何将当前项目发送到goToFunction()?
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!');
}
}
这篇关于Extjs 4.1检查更改监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文