繁体   English   中英

Sencha动态添加监听程序以录制列表

[英]Sencha add dynamically tap listener to record list

我有一个Ext.data.Store和一个带有列表的Ext.Panel。 我使用以下命令动态添加记录:

myStore.add({txt: r});

我想添加一个侦听器,当我单击列表记录时,它将在消息框中显示记录数据。

我该怎么做?

扩展数据存储

   var myStore = Ext.create('Ext.data.Store', {
        storeId: 'MyStore',
        fields: ['txt']
    }); // create()

外部面板

listpanel = new Ext.Panel({
                            layout: 'fit',   // important to make layout as 'fit'
                            items: [
                                {
                                    xtype: 'titlebar',
                                    id: 'myTitle',
                                    docked: 'top',
                                    title: 'Before Change title'

                                },
                                {
                                  //Definition of the list
                                  xtype: 'list',
                                  itemTpl: '{txt}',
                                  store: myStore,
                                }]
                          });

您需要使用Ext.List组件的itemtap事件。

例如

   ....
   ....
   xtype: 'list',
   itemTpl: '{txt}',
   store: myStore,
   listeners : {
         itemtap : function(item, num, record, ev) {
                var myTxt = item.getStore().getAt(num).get('txt');
                Ext.Msg.alert('Message','Tapped record : '+myTxt);
         }
   }
   ....
   ....

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM