4

我的一个页面中有一个 dojo.datagrid。Datagrid 及其存储(通过调用 URL)是通过声明性方法创建的。不是动态/程序化的。

我需要执行一个 javascript 方法,该方法在我的数据网格下方显示一个 div(它需要来自数据网格的少量数据)。我应该只在我的数据网格加载完成后显示 div;而不是在那之前。

我正在寻找为数据网格完成的加载事件。dojo.datagrid 有什么活动吗?我在活动的 dojo.Datagrid 文档列表中没有看到它。

有没有办法检查 dojo datagrid onload 是否完成?

有没有办法使用 dojo.connect 来处理这个?

如果我们有任何方法可以做到这一点,请告诉我...

谢谢,拉杰。

4

4 回答 4

5

数据网格本身实际上从未加载所有可用数据,它仅显示其存储中数据的子选择。

您需要绑定到 store 事件才能捕获 onload 事件。由于存储可以从很多地方加载数据,因此您需要将 onComplete 函数传递给网格存储的 fetch 方法。

grid.store.fetch({onComplete : function (items) { // Do something }});

您还可以通过编程方式创建商店,使用您的 onComplete 侦听器调用 fetch,并且在您完成商店的 onComplete 侦听器中的项目修改后,调用 myGrid.setStore(myStore);

于 2011-03-29T10:25:48.697 回答
3

The DataGrid has an event _onFetchComplete which you could connect to with dojo.connect. Note that it starts with _ though, so it's supposed to be a private/protected kind of event and its behaviour could change in newer Dojo versions. I know it works well in Dojo 1.6.

于 2012-01-31T09:11:51.350 回答
3

As Alex already pointed out, you can react to the (unfortunately) private _onFetchComplete event. With dojo 1.7, this can be achieved with dojo.aspect like:

require(["dojo/aspect", "dojox/grid/DataGrid", ...], function(aspect, DataGrid, ...)
    var myGrid = new DataGrid({ ... });
    aspect.after(myGrid, "_onFetchComplete", function() {
        // Do something with myGrid...    
    });
});
于 2012-03-28T07:32:37.833 回答
0

您可以设置一个计时器来检查数据是否已加载,每隔一秒左右运行一次,直到加载完成(setSelectedIndex 将返回 true):

private var load_check:uint;

    /* start the interval timer when the app is initialized */
protected function init ():void
{
    load_check = setInterval(getTime, 500); // 1/2 second
}
private function getTime():void
{
    if ( !datagrid.setSelectedIndex (0))
        return;
    clearInterval(load_check); // data loaded!
}
于 2011-10-29T11:19:09.430 回答