Sencha Touch itemtap

Ale*_*lex 7 extjs sencha-touch

我有一个sencha touch正在列表中显示的联系人列表.然后,当您单击列表中的名称时,它应向右滑动并说出Hello {联系人姓名}!但是当它现在滑过时它只是说你好!在第29行是项目点击动作发生的地方我相信问题就在这里.我只是不知道如何正确格式化它.以下是我的源代码.

ListDemo = new Ext.Application({
name: "ListDemo",

launch: function() {

    ListDemo.detailPanel = new Ext.Panel({
        id: 'detailpanel',
        tpl: 'Hello, {firstName}!',
        dockedItems: [
            {
                xtype: 'toolbar',
                items: [{
                    text: 'back',
                    ui: 'back',
                    handler: function() {
                        ListDemo.Viewport.setActiveItem('disclosurelist', {type:'slide', direction:'right'});
                    }
                }]
            }
        ]
    });

    ListDemo.listPanel = new Ext.List({
        id: 'disclosurelist',
        store: ListDemo.ListStore,
        itemTpl: '<div class="contact">{firstName} {lastName}</div>',

        listeners:{
            itemtap: function(record, index){               
            ListDemo.detailPanel.update(record.data);
            ListDemo.Viewport.setActiveItem('detailpanel');
            }
        }
    });

    ListDemo.Viewport = new Ext.Panel ({
        fullscreen: true,
        layout: 'card',
        cardSwitchAnimation: 'slide',
        items: [ListDemo.listPanel, ListDemo.detailPanel]
    });

}
Run Code Online (Sandbox Code Playgroud)

});

Stu*_*art 11

传递给itemtap事件的第一个参数不是Tap项目的记录,而是DataView本身.

来自文档:

itemtap:(Ext.DataView this,Number index,Ext.Element item,Ext.EventObject e)点击节点时触发

Listeners will be called with the following arguments:
this : Ext.DataView
    The DataView object
index : Number
    The index of the item that was tapped
item : Ext.Element
    The item element
e : Ext.EventObject
    The event object
Run Code Online (Sandbox Code Playgroud)

您可以使用以下方式获取点击的记录:

dataView.store.getAt(index); // where 'dataView' is 1st argument and 'index' the 2nd
Run Code Online (Sandbox Code Playgroud)


Ale*_*lex 9

itemtap: function(view, index, item, e) {
    var rec = view.getStore().getAt(index);
    ListDemo.detailPanel.update(rec.data);
}
Run Code Online (Sandbox Code Playgroud)

这就是我开始工作的方式.

  • 使用分组列表时,这似乎被打破了. (2认同)