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
.
我敢肯定,某处只是缺少一个细节。
谢谢您的帮助。