1

Dojo 版本是 1.7.2

我有一个 DataGrid,其中填充了来自 MemoryStore 的数据。它工作正常,但在存储中更新对象时,网格中的数据不会更新。

这是网格和商店的连接方式:

formStore = Observable(new MemStore());
formGrid = new DataGrid( {
   store:ObjectStore( {objectStore:formStore} ),
   query:{id:"*"},
   structure:[
      { name:" ", field:"pending", width:"2em",
         formatter:function ( count, rowIdx, cell ) {
            return '<div style="font-size: smaller; text-align: right;">' + count + '</div>';
         }
      },
      { name:" ", field:"name", width:"auto",
         formatter:function ( formName, rowIdx, cell ) {
            return '<div style="white-space: nowrap;">' + formName + '</div>';
         }
      }
   ]

}, "formGrid" );

我有一个更新商店数据的功能:

function updateForms() {
   require( ["dojo/_base/xhr", "dojo/_base/array", "dojox/grid/DataSelection"],
               function ( xhr, array, DataSelection ) {
                  xhr.get( {
                     url:"services/jsonrest/form/",
                     content:{ id:"all" },
                     handleAs:"json",
                     load:function ( forms, io ) {
                        array.forEach( forms, function( form, idx ) {
                           formStore.notify(form, form.id);
                        });
                     }
                  } );
               } );
}

如果此函数运行时商店为空,则项目将显示在 中,DataGrid但一旦项目在网格中,它们就不会更新。这是一个测试系统,Form 对象的一部分在每次调用时都会发生变化。

我最终做的是更改服务器上的方法以始终返回所有项目,然后 javascript 函数如下所示:

function updateForms() {
   require( ["dojo/_base/xhr", "dojo/_base/array", "dojox/grid/DataSelection"],
               function ( xhr, array, DataSelection ) {
                  xhr.get( {
                     url:"services/jsonrest/form/",
                     content:{ id:"all" },
                     handleAs:"json",
                     load:function ( forms, io ) {
                        // reset all the items in the DataGrid
                        formGrid.setItems( forms );
                     }
                  } );
               } );
}

这也有效。选择被保留,DataGrid 不会闪烁。但这有点违背了目的。

我找到了这篇文章,但无法理解它。我尝试了很多东西,但没有任何效果。在本文中,dojo.connect使用旧语法而不是新的dojo.on.

我敢肯定,某处只是缺少一个细节。

谢谢您的帮助。

4

1 回答 1

0

在最新版本的dojo 中,DataGrid 的公共 refresh()方法已被删除。您可以使用.formGrid._refresh()

请注意,他们必须出于某种原因删除了公共功能,这违背了 OOPS 的理念。

作为一般建议,在找不到其他解决方案的情况下,尝试输入formGrid.firebug 控制台的单行模式。当您键入时,.您将获得相关对象的所有成员和属性的列表,包括所有公共成员和属性(通常开头没有 _)和所有私有成员(通常开头有 _)。

如果它在 firebug 中不起作用,请尝试使用 chrome 中的出色控制台。

于 2012-05-10T04:55:11.887 回答