dojox.grid.DataGrid:如何从单击事件访问数据?

发布于 2024-10-06 10:56:47 字数 661 浏览 2 评论 0原文

我正在使用 Dojo 1.5(包括 dojox)。我有一个 dojox.grid.DataGrid,其中每一行代表一个用户。当我单击一行时,我想重定向到 /users/USER_ID 这样的 URL。用户 ID 是网格中的字段之一,因此我在 onRowClick 回调中所需要做的就是获取被单击的行的用户 ID。

click 事件包含 rowIndex 属性,事实上,我在其他地方找到了一篇(相当旧的)帖子,建议我应该能够这样做:(

var row = dijit.byId('grid').model.getRow(e.rowIndex);
/* (Then grab the 0th field of the row, which is the user ID.) */

抱歉,我已经丢失了 URL。)

但是我的网格对象没有 model 属性。这是怎么回事? API 改变了吗? (我的网格当然填充了数据,我可以看到、单击、按列排序等等)。

所以我现在被困住了。请注意,顺便说一句,使用 rowIndex 直接访问网格的底层 dojo.data.ItemFileReadStore 是行不通的。这是因为网格是可排序的,因此不能保证网格的行的顺序与商店的顺序相同。

任何提示将不胜感激。我希望这个问题是明确的,并且足够普遍,任何答案都可以帮助处于我困境的其他人。非常感谢。

I'm using Dojo 1.5 (including dojox). I have a dojox.grid.DataGrid where each row represents a user. When I click a row, I want to redirect to a URL like /users/USER_ID. The user ID is one of the fields in the grid, so all I need to do in my onRowClick callback is to grab the user ID for the row that was clicked.

The click event contains a rowIndex property, and, indeed, I found a (rather old) post elsewhere that suggested I should be able to do:

var row = dijit.byId('grid').model.getRow(e.rowIndex);
/* (Then grab the 0th field of the row, which is the user ID.) */

(Sorry, I've since lost the URL.)

But my grid object has no model attribute. What's up with that? Has the API changed? (My grid certainly is populated with data, which I can see, click, sort by column, et cetera).

So I'm stuck for now. Note, BTW, that it won't work to use rowIndex to directly access the grid's underlying dojo.data.ItemFileReadStore. That's because the grid is sortable, so there's no guarantee that the grid's rows will be in the same order as the store's.

Any hints would be deeply appreciated. I hope that the question is clear, and sufficiently general that any answers can help others in my predicament. Many thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葬花如无物 2024-10-13 10:56:47

我有一个类似的场景,我获取如下值:

onRowClick: function(e) {
   open_link(my_grid._getItemAttr(e.rowIndex, 'object_path'));
}

在本例中,my_grid 是对数据网格的引用,object_path 是我存储对象路径的列。 open_link 当然是我的自定义函数,顾名思义,它请求服务器路径。

因此,只需更改具体细节以适合您的情况,就应该没问题。

I have a similar scenario and I grab the value like this:

onRowClick: function(e) {
   open_link(my_grid._getItemAttr(e.rowIndex, 'object_path'));
}

In this case my_grid is a reference to the datagrid and object_path is the column where I store the path to the object. open_link is of course a custom function of mine that as it implies, requests a server path.

So just change the specifics to suite your case and you should be fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文