简体   繁体   English

将onRowClick绑定到DoJo数据网格(dojox.grid.DataGrid)

[英]Binding onRowClick to a DoJo datagrid (dojox.grid.DataGrid)

I have been able to get the DataGrid to do evertyhing I want except one thing. 除了一件事情,我已经能够使DataGrid做我想做的一切。 I am trying to bind the onRowClick event to a regular javascript function that will do something. 我试图将onRowClick事件绑定到将执行某些操作的常规javascript函数。 I am using Dojo 1.7.2 so the connect(object,event,method) does not work. 我正在使用Dojo 1.7.2,所以connect(object,event,method)无法正常工作。 I tried using the new on(object,event...) to no avail. 我尝试使用新的on(object,event ...)无济于事。 What am I doing wrong? 我究竟做错了什么?

In between tags but below changeValue()[A function I wrote and known working] and the dojo.require... In other words, the very last thing in the block. 在标签之间,但在changeValue()[我编写并已知有效的函数]和dojo.require之下。换句话说,代码块中的最后一件事。 I know something is wrong with the syntax of the on method but can not figure out what. 我知道on方法的语法有问题,但无法弄清楚是什么。

var ngrid = dijit.byId('grid');
dojo.on(ngrid,"onRowClick",changeValue());

Fix for your code; 修正您的代码; as i believe the function you'd want to bind is the actual changeValue and not what it might return, try this 因为我相信您要绑定的功能是实际的changeValue而不是它可能返回的值,请尝试执行此操作

dijit.byId('grid').connect("onRowClick", changeValue)

.on makes some magic to the prefixed * on *Something so try with .connect instead. .on使* 带有前缀*的东西变得有些神奇,因此请尝试使用.connect代替。 Best practice is to register the listener via the object itself so it will get disconnected as grid is destroyed. 最佳做法是通过对象本身注册侦听器,以便在销毁网格时断开连接。 Above does the call as an extension to the grid object so you should not pass the grid reference as first parameter. 上面的调用是对网格对象的扩展,因此您不应将网格引用作为第一个参数传递。

This is the correct syntax with the on method 这是on方法的正确语法

you have to remove the 'on' part of the event's name string 您必须删除事件名称字符串的“ on”部分

var ngrid = dijit.byId('grid');
dojo.on(ngrid,"rowClick",changeValue());

Similar to @mschr's answer, here is also how to get the data associated with the row clicked. 与@mschr的答案类似,这也是如何获取与单击的行关联的数据。

dojo.connect(grid, "onRowClick", function(e) {
     var dataItem = grid.selection.getSelected();
     // call you change method here with dataItem
});

and an example 和一个例子

http://jsfiddle.net/cswing/T27hv/ http://jsfiddle.net/cswing/T27hv/

Assign the jsid ="mygrid" attribute to your Datagrid . jsid ="mygrid"属性分配给您的Datagrid。 Pass your jsid in the dojo connect you don't have to do dijit.byId() . 在dojo连接中传递您的jsid ,而不必执行dijit.byId()

 dojo.connect(mygrid, "onRowClick", changeValue); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM