开发者

Ext.dispatch from within itemTap listener?

A similar question was answered here: How to add itemtap

But when I try to move my Ext.dispatch() code from onItemDisclosure: to listeners: {itemtap:}, it doesn't work.

The Ext.dispatch originally lived here:

    onItemDisclosure: {
        scope: this,
        handler: function (record) {
            // Call the controller's "show" action
            Ext.dispatch({
                controller: myApp.controllers.products,
                action: 'show',
                id: record.ge开发者_如何学CtId()
            });
        }
    }

But now I want it to live here (to remove the disclosure button and make the whole row selectable):

    listeners: {
        scope: this,
        itemTap: function (record) {
            alert('!!!');
            // Call the controller's "show" action
            Ext.dispatch({
                controller: myApp.controllers.products,
                action: 'show',
                id: record.getId()
            });
        }
    }

EDIT: The function within the itemTap: listener is called (the alert is displayed), but the 'show' action is not called in the controller as it is when the Ext.dispatch lived within the onItemDisclosure:.


assuming you are doing this inside of a list as in the other question, the itemtap event is passed 4 arguments: Ext.DataView this, Number index, Ext.Element item, Ext.EventObject e .

so you want to do something like

itemtap: function(dataView, index, item, e) {
    Ext.dispatch({
            controller: myApp.controllers.products,
            action: 'show',
            id: index
        });
}

That's assuming getId() is just giving you the record's index. If it's giving you something else, you could get the record object itself by doing

dataView.getStore().getAt(index) /* .getId() */

hope that helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜