【问题标题】:add listener for multiple element sencha touch为多元素煎茶触摸添加监听器
【发布时间】:2013-09-13 04:53:57
【问题描述】:

您好,我是煎茶触摸的新手。请在下面查看我的代码

    Ext.define('blackbutton.view.Login.Login', {
extend: 'Ext.Container',
xtype: 'loginview',
id:'loginview',
requires: [    
  'Ext.field.Password',
  'blackbutton.store.Login.LoginLS'
],

config: {
    style: 'background-color:#0B0B0C',
    cls: 'core',
    scrollable: {direction: 'vertical', directionLock: true},
     html      : '<section class="nt_contentWrap">'+

     ' <img src="resources/images/profile_header_signup.jpg" width="320" height="142"  alt=""/> <br>'+
      '<br>'+
        '<span class="title"> Login           </span> '+
  ' <ul class="ul-na">'+
          ' <li><input type="text" placeholder="Email" name="bbid"></li>'+

          ' <li>'+
  ' <input type="text" placeholder="Password"  maxlength="11" name="bbpassword"></li>'+
 '</ul>'+


'<button type="signup" id="login">Log In</button>'+
'<button type="signup" id="sigup" >Sign up</button>'+




'</section>',

    listeners : [
        {
            element  : 'element',
            delegate : 'button#sigup',
            tap      : function () {
                alert('test');
            }
        },
        {
            element  : 'element',
            delegate : 'button#login',
            tap      : function () {
                alert('login');
            }
        }

    ]
    }

    });

我需要为两个按钮添加监听器。分别是注册按钮和登录按钮。点击事件似乎没有火。

但是,如果我只为一个按钮添加监听器。

listeners : 
{
    element  : 'element',
    delegate : 'button#sigup',
    tap      : function () {
        alert('test');
    }
}

注册按钮的点击事件能够触发。有什么想法吗?

【问题讨论】:

    标签: events listener element sencha-touch-2.1


    【解决方案1】:

    你可以根据目标ID做以下技巧

    listeners: {
        tap: {
                    element: 'element',
                    delegate: ['button#sigup', 'button#login'],
                    fn: "DoSomething"
             }
    
     }
    
    
    //.....
    
    function DoSomething(e){
      if (e.target.id=="sigup"){
        //signup
      }
      else{
        //login
      }
    }
    

    【讨论】:

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