2011-11-18 72 views
0

我正在创建一个网格面板,并且希望为每行添加一个事件。以下是我的代码extjs rowselect无法正常工作

var locationdata = Ext.create('Ext.data.Store', { 
    fields:['name'], 
    storeId:'simpsonsStore', 
    data:{'items':[ 
       { 'name': 'Lisa'} 
      ]}, 
     proxy: { 
      type: 'memory', 
      reader: { 
       type: 'json', 
       root: 'items' 
      } 
     } 

}); 

hintBox = Ext.create('Ext.grid.Panel', { 
    title: 'Location List', 
    store: locationdata, 
    columns: [ 
     { header: 'Name', dataIndex: 'name' , flex:1 } 
    ], 
    flex: 5 
}); 
hintBox.getSelectionModel().on('rowselect', function(sm, rowIdx, r) { 
    alert("row selected"); 
}); 

我在anothor面板中将hintBox添加到呈现给body的面板中。

这段代码有什么问题?

回答

1

选择模型没有事件 'rowselect',在ExtJS的4 selectiom模型只有SelectionChange事件。

hintBox.getSelectionModel().on('selectionchange', function(sm, selectedRows, opts) { 
     //selected rows is an array of models and if you want just one row selected, 
     //you have to config the grid so it only accepts one selection i think is selType: 'SINGLE' or 'SIMPLE' 
     // and after that selectedRows[0] will be the selected row 
     alert("rows selected"); 
});