简体   繁体   English

将事件处理程序附加到尚未在DOM中的dojox DataGrid存储中的元素上

[英]Attaching event handlers to elements in a dojox DataGrid store that are not in the DOM yet

I'm using a dojox.DataGrid in Dojo 1.8, and each of the rows has a button that I attach an onclick handler to. 我在Dojo 1.8中使用了dojox.DataGrid,并且每一行都有一个按钮,我将onclick处理程序附加到该按钮。 Up to 25 rows, I can easily attach the onclick event to each button this way: 最多25行,我可以通过以下方式轻松地将onclick事件附加到每个按钮:

dojo.connect(dojo.byId('button1'), 'onclick', this, 'callback')

However, when there are more than 25 items in the store, the 26th+ rows are not written to the DOM yet, so the line above will fail for the 26th (and oddly attaches the event to the top level DOM element) since dojo.byId('button26') returns null. 但是,当商店中的商品超过25个时,第26个以上的行尚未写入DOM,因此,由于dojo.byId,上面的行将在第26个行中失败(并将事件奇怪地附加到顶级DOM元素)。 ('button26')返回null。 I know this is because of the paging feature of the DataGrid. 我知道这是由于DataGrid的分页功能所致。

Is there any way to attach event handlers to all of the items in the store itself, or to "future" elements on the DOM that will be there when the DataGrid retrieves the next page? 是否可以将事件处理程序附加到商店本身中的所有项目,或者将DataGrid检索下一页时将出现的DOM上的“未来”元素附加到存储中? Thanks! 谢谢!

Since the object does not exist you, you will have to attach to the fetch or store events to know when they will be rendered. 由于您不存在该对象,因此您必须附加到访存或存储事件才能知道何时渲染它们。

Either use the _onFetchComplete from the grid, or listen to the onComplete from the store. 使用网格中的_onFetchComplete或从商店中监听onComplete。

Here are a couple of related stackoverflow: how to check dojo.datagrid loading completed? 以下是一些相关的stackoverflow: 如何检查dojo.datagrid加载是否完成?

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

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