2011-06-11 109 views
7

我有一个sencha touch在列表中显示的联系人列表。然后,当你点击列表中的一个名字时,它应该向右滑动,并说Hello {contact name}!但是当它现在滑过时,它只是说第29行的Hello!是行动发生的地方,因为item tap我相信问题在这里。我只是不知道如何正确格式化。以下是我的源代码。Sencha Touch itemtap

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] 
    }); 

} 

});

回答

11

传递给itemtap事件的第一个参数不是列表项的记录,而是数据视图本身。

从文档:

itemtap:(Ext.DataView此,数量指数,Ext.Element的项目, 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 
抽头

您可以通过抢挖记录:

dataView.store.getAt(index); // where 'dataView' is 1st argument and 'index' the 2nd 
+0

我只是在学习sencha touch什么是dataview对象,被挖掘的项目的索引,项目元素和事件对象。另外,dataView是第一个参数,'index'是第二个参数。谢谢你的帮助。 – Alex 2011-06-12 05:59:50

+0

List继承自DataView,'itemtap'事件是从DataView基类继承的事件。因此,使用List时文档有点混乱。事件处理程序的第一个参数包含对您的List实例的引用(相当于您示例中的变量“ListDemo.listPanel”)。 '索引'参数是指被轻敲项目落入例如列表中的位置。第一个列表项tapped给出index = 0,第二项tapped给出index = 1等。对于简单的用例,你可以忽略项目和e参数 - 再加上我的空间不足.. :) – Stuart 2011-06-13 11:19:40

+0

这似乎是破坏时与分组列表一起工作。 – Art 2011-09-15 08:11:26

9
itemtap: function(view, index, item, e) { 
    var rec = view.getStore().getAt(index); 
    ListDemo.detailPanel.update(rec.data); 
} 

这就是我如何运作。

+2

使用分组列表时,这似乎被破坏。 – Art 2011-09-15 08:11:48

+1

请注意,在Sencha Touch 2中,更新方法现在是setData() – cyberwombat 2012-01-29 21:25:24