日期:2014-05-16  浏览次数:20725 次

Ext gride 点击一行数据,获得这行数据的信息
我现在的需求是,选中一行数据,点击删除后,先弹窗显示选中这一行数据的信息,然后删除数据。点击一行数据数据,然后删除的功能我已经实现了,现在就是删除前,我不知道怎么获得选中这一行的数据信息,我用的是Ext4.0.7...... 

js 代码如下 

Ext.onReady(function(){ 
var itemsPerPage = 5; // set the number of items you want per page 

var store = Ext.create('Ext.data.Store', { 
  id:'simpsonsStore', 
  autoLoad: false, 
  fields:['id', 'name', 'age'], 
  pageSize: itemsPerPage, // items per page 
  proxy: { 
  type: 'ajax', 
  url: 'info_getinfo.action', // url that will load data with respect to start and limit params 
  reader: { 
  type: 'json', 
  root: 'list', 
  totalProperty: 'count' 
  } 
  } 
}); 

// specify segment of data you want to load using params 
store.load({ 
  params:{ 
  start:0, 
  limit: itemsPerPage 
  } 
}); 

var grid=Ext.create('Ext.grid.Panel', { 
  title: '用户信息', 
  store: store, 
  columns: [ 
  {header: '编号', dataIndex: 'id'}, 
  {header: '姓名', dataIndex: 'name', flex:1}, 
  {header: '年龄', dataIndex: 'age'} 
  ], 
  width: 400, 
  height: 300, 
  dockedItems: [{ 
  xtype: 'pagingtoolbar', 
  store: store, // same store GridPanel is using 
  dock: 'bottom', 
  displayInfo: true 
  },{ 
  xtype: 'toolbar', 
  items: [{ 
  text:'添加用户', 
  tooltip:'添加用户', 
  iconCls:'add' 
  }, '-', { 
  text:'删除用户', 
  tooltip:'删除用户', 
  iconCls:'delete', 
  handler: function(){ 
  var selection = grid.getView().getSelectionModel().getSelection()[0]; 
  if (selection) { 
  store.remove(selection); 
  } 
  } 
  },'-',{ 
  text:'修改用户', 
  tooltip:'修改用户', 
  iconCls:'update' 
  },new Ext.form.TextField({ 
  emptyText:"搜索", 
  width:100 
  })] 
  }], 
  renderTo: Ext.getBody() 
}); 
});

------解决方案--------------------
你的数据信息不就全在selection 里面么
selection.data
------解决方案--------------------
//首先获取selectionmodel
var sm = grid.getSelectionModel();
//再取出选中的记录集
var records = sm.getSelection();
//考虑到多选的话要用循环
for(var i=0;i<records.length;i++){
var name = records[i].get('name');//获取姓名,其它类似
}