【问题标题】:Attaching event handlers to elements in a dojox DataGrid store that are not in the DOM yet将事件处理程序附加到 dojox DataGrid 存储中尚未在 DOM 中的元素
【发布时间】:2013-09-08 14:31:24
【问题描述】:

我在 Dojo 1.8 中使用 dojox.DataGrid,每一行都有一个按钮,我将一个 onclick 处理程序附加到该按钮。最多 25 行,我可以通过这种方式轻松地将 onclick 事件附加到每个按钮:

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

但是,当商店中的商品超过 25 件时,第 26 行以上的行还没有写入 DOM,因此上面的行将在第 26 行失败(并且奇怪地将事件附加到顶级 DOM 元素),因为dojo.byId('button26') 返回 null。我知道这是因为 DataGrid 的分页功能。

有没有办法将事件处理程序附加到商店本身的所有项目,或附加到 DataGrid 检索下一页时将存在的 DOM 上的“未来”元素?谢谢!

【问题讨论】:

    标签: javascript datagrid dojo dojox.grid.datagrid


    【解决方案1】:

    由于您不存在该对象,因此您必须附加到 fetch 或 store 事件才能知道它们何时会被呈现。

    要么使用网格中的 _onFetchComplete,要么收听商店中的 onComplete。

    这里有几个相关的stackoverflow: how to check dojo.datagrid loading completed?

    【讨论】:

    • 谢谢,成功了。我刚刚添加了 dojo.connect (this.grid, "_onFetchComplete", function () { .... })
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    相关资源
    最近更新 更多