2012-12-11 17 views
0

我有一個Ext.grid.Panel,其中包含一個用於dblclick的偵聽器。它看起來像這樣:Ext.grid.Panel - 如何訪問行數據

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

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

當行被雙擊,我想在新頁面中打開一個URL。爲了確定URL,我需要訪問行數據 - 或者作爲我的JSON中作爲面板商店的「行」。我將如何訪問這些數據?

+0

我不認爲網格面板直接有一個dblclick事件,您是否使用行選擇模型? – dougajmcdonald

回答

1

那麼,事件是itemdblclick(無dblclick)。該行作爲參數傳遞給處理程序。

例如,後續的樣品中,當你在一排雙擊你可以看到一個警告彈出窗口顯示選定辛普森名稱:

Ext.create('Ext.data.Store', { 
    storeId:'simpsonsStore', 
    fields:['name', 'email', 'phone'], 
    data:{'items':[ 
     { 'name': 'Lisa', "email":"[email protected]", "phone":"555-111-1224" }, 
     { 'name': 'Bart', "email":"[email protected]", "phone":"555-222-1234" }, 
     { 'name': 'Homer', "email":"[email protected]", "phone":"555-222-1244" }, 
     { 'name': 'Marge', "email":"[email protected]", "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() 
});​ 

你也可以看到它在這裏工作:http://jsfiddle.net/lontivero/utjyd/1/

祝你好運!