一个关于获取record的id 的问题,请看下面删除的函数deleteUser
[code="java"]UserList = Ext.extend(Ext.Panel, {
layout: 'fit',
autoWidth: true,
store: 'UserStore',
initComponent: function() {
this.items = [
{
xtype: 'editorgrid',
id:'grid_id',
store: 'UserStore',
border: false,
loadMask: true,
view: new Ext.grid.GridView({forceFit:true}),
selModel: new Ext.grid.CheckboxSelectionModel({width:20}),
columns: [new Ext.grid.RowNumberer({width: 30}),
{
xtype: 'gridcolumn',
header: '姓名',
sortable: true,
dataIndex: 'name',
width: 100,
editor: {xtype: 'textfield'}
},
{
xtype: 'gridcolumn',
header: '电子邮箱',
sortable: true,
dataIndex: 'email',
width: 150,
editor: {xtype: 'textfield'}
},
{
xtype: 'gridcolumn',
header: '用户名',
sortable: true,
dataIndex: 'username',
editable:false,
width: 100,
editor: {xtype: 'textfield'}
},
{
xtype: 'booleancolumn',
dataIndex: 'enable',
header: '可用',
sortable: true,
width: 100,
editor: {
xtype: 'checkbox',
boxLabel: '是否可用'
}
}
]
}
];
this.bbar = {
xtype: 'paging',
pageSize: 10,
store: 'UserStore',
displayInfo: true,
displayMsg: '显示第{0}条到{1}条记录,一共{2}条',
emptyMsg:'没有记录',
items: [
{
xtype: 'button',
text: '提交更新',
handler:this.saveUser
}
]
};
this.tbar = {
xtype: 'toolbar',
items: [
{
xtype: 'tbfill'
},
{
xtype: 'tbseparator'
},
{
xtype: 'button',
id: 'deleteUser',
text: '删除',
handler:this.deleteUser
},
{
xtype: 'tbseparator'
}
]
};
UserList.superclass.initComponent.call(this);
},
deleteUser :function() {
var userIds = Ext.getCmp("grid_id").selModel.selections.keys;
//问题出在这里:我想获取被选取的record的id,但获得的Id值如ext-record-21,ext-record-22....
// 看网上好多人用var userIds = this.selModel.selections.keys,在这里我不行,所以用getCmp来获取表格对象,可能是这个的问题,但不确定。请高手可以帮忙看一下,谢谢,
if (userIds.length <= 0) {
Ext.MessageBox.alert('提示', '请选择要删除的数据');
return;
}
var submitFun = function(buttonId, text, opt) {
if (buttonId == 'yes') {
micrite.util.ajaxRequest({
url: 'DeleteUser.action',
params:{'userIds':userIds},
success:function(r,o){
//var res = Ext.decode(r.responseText);
//if (res && res.success){
this.store.reload();
//}
},
failure:Ext.emptyFn
},this);
}
};
Ext.Msg.show({
title:'删除操作',
msg: '是否删除',
buttons: Ext.Msg.YESNO,
scope: this,
fn: submitFun
//icon: Ext.MessageBox.QUESTION
});
},
[/code]