Javascript Extjs Grid - 单击事件侦听器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13795880/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 12:55:14  来源:igfitidea点击:

Extjs Grid - Click event listener

javascriptextjsextjs4clickgridpanel

提问by Noon

I did successfully add a row double click event listener to my grid by:

我确实通过以下方式成功地向我的网格添加了一个行双击事件侦听器:

listeners : {
    itemdblclick: function(dv, record, item, index, e) {
        alert('working');
    }
},

Now, I need to get the exact value in third column at the selected row, how can I do that ?

现在,我需要在所选行的第三列中获取确切值,我该怎么做?

EDIT

编辑

Okay found it:

好的找到了:

listeners: {
    itemclick: function(dv, record, item, index, e) {
        alert(record.get('name'));
    }
}

but seems like the result of record.get('name')is not a text! its an object but I cannot handle it as if it a text. any body has any idea ?

但似乎结果record.get('name')不是文本!它是一个对象,但我无法像处理文本一样处理它。任何机构有任何想法?

EDIT

编辑

For example, if I pass the name to search function: Search(record.get('name'));this won't work. but if I pass it this way: Search('Mike');it works !

例如,如果我将名称传递给搜索功能:Search(record.get('name'));这将不起作用。但是如果我这样通过它:Search('Mike');它起作用了!

采纳答案by sra

Ensure that

确保这件事

  • Your property name is really lowercase 'name' and not 'Name'
  • Print the value of the field into the console with console.log(record.get('name'))or use the direct access by typing console.log(record.data.name)or console.log(record.data['name']). Basically all should return the same.
  • To cast a value to string apply ''on the fly like var myVar = 2; myVar = myVar + ''; // now print 20 as string
  • 您的财产名称实际上是小写的“名称”而不是“名称”
  • 使用console.log(record.get('name'))或 通过键入console.log(record.data.name)或使用直接访问将字段的值打印到控制台中console.log(record.data['name'])。基本上都应该返回相同的。
  • 将值转换为字符串应用'',例如var myVar = 2; myVar = myVar + ''; // now print 20 as string

回答by AJJ

Try with,

试试看,

listeners: {
itemclick: function(dv, record, item, index, e) {
 var selectedRec = dv.getSelectionModel().getSelected();          
 alert(selectedRec.get('name')); //Will display text of name column of selected record
}