【问题标题】:Sencha Touch 2: Listen for tap on two different HTML buttonsSencha Touch 2:聆听点击两个不同的 HTML 按钮
【发布时间】:2014-04-07 06:10:41
【问题描述】:

在我的嵌套列表中,我有两个 html 按钮。我已经有一个嵌套列表的侦听器,它显示detailCard 持有两个按钮,但我想添加另一个侦听器,它在按下其中一个按钮时执行一些操作。每个按钮都有不同的作用,因此我无法将其中一个按钮委托给特定功能。有没有办法做类似的事情:

listeners : {
element  : 'element',
delegate : 'button.mybutton',
tap      : function() {
    //...
  }
}

但是对于多个代表,每个代表都做其他事情?

【问题讨论】:

    标签: javascript extjs sencha-touch sencha-touch-2


    【解决方案1】:

    您可以向按钮添加数据属性并做出相应反应:

    <button data-do="showDetailCard">
    <button data-do="anotherAction">
    
    // ...
    
    listeners: {
        tap: {
            element: 'element',
            delegate: 'button',
            fn: 'doAction'
        }
    }
    
    // ...
    
    function doAction(event) {
        var do = event.target.dataset.do;
        if (do === 'showDetailCard') {
            // show detail card
        } else if (do === 'anotherAction') {
            // do another action
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多