3

我创建了一个基于表格的模板,所以我可以获得类似网格的感觉。我的问题是,当我单击表格行时,如何获得弹出警报(带有 td 信息)。

这是我的 getUserList.js 文件

    Ext.regModel("User", {
            fields: [
                "id",
                "name",
                "username",
                "password",
                "email",
                "phone"
            ]
    });

    var myStore = new Ext.data.Store({
        model: 'User',
        proxy: {
            type: 'ajax',
            url : '../sencha/php/getUserList.php',
            reader: {
                type: 'json',
                root: 'results'
            }
        },
        autoLoad: true
    }); 


    var tpl = new Ext.XTemplate(//'<h2>test information</h2>'
    '<table id="userTable"',
        '<tpl for=".">',

                '<tr>',
                    '<td class="x-view-over">',
                        '<span class="thumb-wrap">{id}</span>',
                    '</td>',
                    '<td class="x-view-over">',
                        '<span class="thumb-wrap"><a onclick="alert(tpl.name)">{name}</a></span>',
                    '</td>',
                    '<td>',
                        '{username}',
                    '</td>',
                    '<td>',
                        '{password}',
                    '</td>',
                    '<td>',
                        '{email}',
                    '</td>',
                    '<td>',
                        '{phone}',
                    '</td>',
                '</tr>',
        '</tpl>',
    '</table>',
        '<div class="x-clear"></div>'
    );

    var panel = new Ext.extend(Ext.Panel,{
        id:'images-view',
        frame:true,
        //width:535,
        autoHeight:true,
        collapsible:true,
        title:'Simple DataView',
        initComponent: function() {
            panel.superclass.initComponent.call(this);
        },

        items: new Ext.DataView({
            store: myStore,
            tpl: tpl,
            autoHeight:true,
            multiSelect: true,
            overItemCls:'x-view-over',
            itemSelector:'tr',
            emptyText: 'No images to display'
        })
    });

      Ext.reg('userPanel', panel);

感谢您提供的任何建议。

4

1 回答 1

5

好吧,没有人帮助我,我终于想通了。以下是我如何在模板中获取行的 ID:

         var newDV = new Ext.DataView({
            store: myStore,
            tpl: tpl,
            autoHeight:true,
            //multiSelect: true,
            //overItemCls:'x-view-over',
            itemSelector:'tr',
             listeners: {
                itemtap: function(dv, idx, itm, e) {
                    alert(dv.getStore().getAt(idx).getId());
                }
            }

        })
于 2011-01-31T20:39:11.873 回答