我在第一次调用函数时创建并加载数据网格,之后我尝试使用以下代码刷新数据网格。
function loadgrid(str)
{
require(['dojo/_base/lang', 'dojox/grid/DataGrid', 'dojo/data/ItemFileWriteStore', 'dojo/dom', 'dojo/domReady!'],
function(lang, DataGrid, ItemFileWriteStore, dom)
{
var data =
{
identifier: "id",
items: []
};
var data_list = JSON.parse(str);
for(var i = 0, l = data_list.length; i < l; i++)
{
data.items.push(lang.mixin({ id: i+1 }, data_list[i]));
}
var store = new ItemFileWriteStore({data: data});
if(!document.getElementById("grid"))
{
var grid = new DataGrid(
{
id: 'grid',
store: store,
structure: layout,
rowSelector: '20px',
rowsPerPage:40
});
grid.layout.setColumnVisibility(1,false);
grid.placeAt("gridDiv");
grid.startup();
}
else
{
var grid = dijit.registry.byId("grid");
grid.setStore = store;
grid.render();
}
});
}
</script>
运行良好但网格仍在旧数据存储中。这有什么不对?
答案 0 :(得分:0)
而不是这个
var grid = dijit.registry.byId("grid");
grid.setStore = store;
grid.render();
我必须使用
var grid = dijit.registry.byId("grid");
grid.setStore(store);