我在想我忽略了一些简单的事情——我非常接近完成这项工作。:)
我有一个需要使用服务器信息更新的网格。
这是它应该工作的方式:
- 用户选择一个项目
- 使用选定的项目 ID 进行 JsonRest 查询
- 更新网格 - 显示与所选项目相关的注释
以下是网格的设置方式:
函数 noteTabSetup() {
var store = JsonRest({target:"//localhost/program/notes", idAttribute:"id"});
var structure = [{ field: 'id', name: 'Id', width: '5em' },
{ field: 'name', name: 'Name', width: '12%' },
{ field: 'description', name: 'Description' }];
var noteGrid = new Grid({
id: 'noteGrid',
pageSize: 20,
store: store,
cacheClass: Cache,
structure: structure,
filterServerMode: true,
selectRowTriggerOnCell: true,
bodyLoadingInfo: "Loading notes ...",
bodyEmptyInfo: "No notes found",
modules: [SingleSort, VirtualVScroller, moveColumn,
selectColumn, dndColumn, selectRow, Filter]}, noteTab);
noteGrid.startup();
当一个项目被选中时,选中的项目 ID 被传递给:
function noteLoad(itemId) {
console.log("In NoteLoad");
var grid = registry.byId("noteGrid");
if (!itemIds || 0 === itemIds.length) { console.log("no ItemId chosen"); }
else {
console.log("In NoteLoad with an itemId");
grid.model.clearCache();
// Error on second run
grid.store.query({ find: "ByItem", item: itemId }).then(function(result) {
grid.setStore(new ItemFileReadStore({data: {items : result}}));
});
grid.body.refresh();
console.log("model: " + grid.rowCount());
};
};
在选择的第一个项目上,一切正常 - 查询触发,网格更新为与所选项目相关的注释。在选择的第二个项目上,我从 firebug 收到此错误:
TypeError: grid.store.query is not a function
grid.store.query({ find: "ByItem", item: itemIds }).then(function(result) {
-----------------------------------^
有任何想法吗?!先感谢您。克里斯
感谢您的回复 - 商店被 ItemFileReadStore 取代是有道理的。如果可能的话,我想直接使用 JsonRest 来更新网格。
我根据您的评论尝试了一些变体,但没有运气:
查询触发并返回结果。网格未更新:
grid.model.clearCache();
grid.store.query({ find: "ByItem", item: itemIds }).then(function(results){
console.log('notes: ' + results[0].name);
});
grid.body.refresh();
错误:grid.store.fetch 不是函数:
grid.store.fetch({ query: { find: "ByItem", item: itemIds }});
Dojo.js 中的语法错误(第 15 行):
grid.store.query({ find: "ByItem", item: itemIds }).then(function(result) {
grid.setStore(new JsonRest({data: {items : result}}));
});
我进行了很多搜索,但找不到从 JsonRest 对象更新网格的好例子。谢谢你。