简体   繁体   English

Ext.grid.Panel-如何访问行数据

[英]Ext.grid.Panel - how to access row data

I have an Ext.grid.Panel with a listener for dblclick. 我有一个带有dblclick监听器的Ext.grid.Panel。 It looks like this: 看起来像这样:

listeners: {
    dblclick: {
        fn : function() {

               console.log("double click event processed");
        },
        element: 'el'
    }                
}

When a row is double clicked, I would like to open a URL in a new page. 双击某行时,我想在新页面中打开一个URL。 In order to determine the URL, I need access to row data - either that, or to the "row" in my JSON that serves as the Panel's store. 为了确定URL,我需要访问行数据-可以访问行数据,也可以访问用作面板存储的JSON中的“行”。 How would I access this data? 我将如何访问这些数据?

Well, the event is itemdblclick (no dblclick). 好吧,该事件为itemdblclick(无dblclick)。 And the row is passed as an argumento to the handler. 并将该行作为自变量传递给处理程序。

For example, in the follow sample, when you double click on a row you can see an alert pop-up window displaying the selected Simpson name: 例如,在以下示例中,当您双击一行时,您会看到一个警报弹出窗口,其中显示了选定的辛普森名称:

Ext.create('Ext.data.Store', {
    storeId:'simpsonsStore',
    fields:['name', 'email', 'phone'],
    data:{'items':[
        { 'name': 'Lisa',  "email":"lisa@simpsons.com",  "phone":"555-111-1224"  },
        { 'name': 'Bart',  "email":"bart@simpsons.com",  "phone":"555-222-1234" },
        { 'name': 'Homer', "email":"home@simpsons.com",  "phone":"555-222-1244"  },
        { 'name': 'Marge', "email":"marge@simpsons.com", "phone":"555-222-1254"  }
    ]},
    proxy: {
        type: 'memory',
        reader: {
            type: 'json',
            root: 'items'
        }
    }
});

Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    store: Ext.data.StoreManager.lookup('simpsonsStore'),
    columns: [
        { text: 'Name',  dataIndex: 'name' },
        { text: 'Email', dataIndex: 'email', flex: 1 },
        { text: 'Phone', dataIndex: 'phone' }
    ],
    height: 200,
    width: 400,
    listeners: {
        itemdblclick: {
           fn : function(grid, record) {
               alert(record.get('name'));
           }
        }
    },                

    renderTo: Ext.getBody()
});​

You also can see it working here: http://jsfiddle.net/lontivero/utjyd/1/ 您也可以在这里看到它的工作: http : //jsfiddle.net/lontivero/utjyd/1/

Good luck! 祝好运!

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

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