sencha-touchsencha-touch-2senchatouch-2.4

Get button from dataview on tap in Sencha 2


In my Sencha Touch 2.4.1 application, I have a dataview where each row has some text, and two buttons.

In my dataview, I have the following listener:

listeners: {
    itemtap: function(dataview, index, target, record, e) {
        // for testing
        var el = Ext.fly(target);
        var el2 = e.getTarget(null, null, true);
    }   
}

What I want to do is get the element that was tapped, and if it's a button, get that specific button and do something with it (like change its background color).

How can I get the specific button?

I have tried functions here and have tried to get the id and html of the element, but I've had no luck - usually the value or function is undefined. Tried e.target, el.dom...

How can I get the id, itemId, or cls of the button that was clicked?


Solution

  • You should use e.getTarget. For example, if your button has class "ux-dataview-button" then itemTap should be like this:

    itemtap: function(dataview, index, target, record, e) {
        if (e.getTarget('.ux-dataview-button')) {
            // your code
        } else {
            // your code
        }
    }