EXTJS 3.4如何在选择更改时获取记录数据视图

EXTJS 3.4 HOW TO GET RECORD DATAVIEW ON selectionchange

本文关键字:获取 记录 视图 数据 选择 EXTJS      更新时间:2023-09-26

如何在使用Ext.DataView时获得选择更改的记录?

我想在selectionchange事件函数中获得值'IdPrd'。

var tpl_ram = new Ext.XTemplate(
    '<ul>',
        '<tpl for=".">',
            '<li class="phone">',
                '<img width="64" height="64" src="data/catalogo/ramos/imagenes/{IdRm}/{IdRm}.jpg" />',
                '<strong>{NomRm}</strong>',
                '<span>{DescRm}</span>',
            '</li>',
        '</tpl>',
    '</ul>');
var ramos_dw = new Ext.DataView({
    tpl: tpl_ram,
    store: ramos_productos,
    id: 'ramos_dw',
    itemSelector: 'li.phone',
    overClass: 'phone-hover',
    singleSelect: true,
    autoScroll: true,
    autoHeight: true,
    emptyText: 'SIN RESULTADOS QUE MOSTRAR',
    listeners: {
        'click': function() {},
         selectionchange: {
            fn: function(dv, nodes) {
                //i want on selection get value 'IdPrd'
                var record = nodes[0];
                console.log("advert id - " + record.get('IdPrd'))
            }
        }
    }
});

不清楚您的商店模型是什么样子的。但解决方案是先获取数据对象。

所以代码应该是:

var recordData = nodes[0].getData();
// keep in mind that user can select more than 1 node --> nodes[0] 
console.log("advert id - " + recordData['IdPrd'])

您还可以简单地将debugger;放入selectionchange函数侦听器中,并探索您在特定示例中获得的nodes对象究竟是什么样子。