Javascript 获取选定的行列值 extjs 网格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14165617/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get selected row column value extjs grid
提问by ramiromd
I have a users grid. To delete one, select your row and click a button "delete". But, this not work. My code is:
我有一个用户网格。要删除一个,请选择您的行并单击“删除”按钮。但是,这行不通。我的代码是:
var row = userGrid.getSelectionModel().getSelection();
console.log(row.get('dni'))
Firefox says:
火狐说:
TypeError: row.get is not a function
类型错误:row.get 不是函数
Any idea ?.
任何的想法 ?。
回答by Avinash T.
It is good practice to always check hasSelection()like -
总是hasSelection()像这样检查是一种很好的做法-
if (userGrid.getSelectionModel().hasSelection()) {
var row = userGrid.getSelectionModel().getSelection()[0];
console.log(row.get('dni'))
}
回答by dbrin
perhaps because
也许是因为
getSelection( ) : Ext.data.Model[]
Returns an arrayof the currently selected records.
getSelection() : Ext.data.Model[]
返回当前选定记录的数组。
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.selection.Model-method-getSelection
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.selection.Model-method-getSelection

