【问题标题】:Extjs 4.1 Check Change ListenerExtjs 4.1 检查更改监听器
【发布时间】:2012-09-22 13:16:10
【问题描述】:

处理菜单检查项事件的正确方法是什么?

我有这个菜单:

 {
      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- 有没有办法使用一个监听器并在其中收集所有不同的功能?

2- 如您在代码中所见,如何将当前项目发送到 goToFunction()?

【问题讨论】:

    标签: extjs extjs4.1


    【解决方案1】:

    看起来监听器并不经常被触发。您可以改用 checkHandler 配置。

    【讨论】:

      【解决方案2】:

      只需为每个菜单检查项制作一个处理程序:

      items: [{
          xtype: 'menucheckitem',
          text: 'select all' ,
          id: 'first' ,
          listeners: {
              checkchange: me.myHandler
          }
      },{
          xtype: 'menucheckitem',
          text: 'select specific' ,
          id: 'second' ,
          listeners: {
              checkchange: me.myHandler
          }
      }]
      

      您的处理程序定义如下:

      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!');
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2011-10-12
        • 2012-11-25
        • 2012-01-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-12
        • 1970-01-01
        相关资源
        最近更新 更多