Javascript 使用服务器端数据刷新gridx

Javascript 使用服务器端数据刷新gridx,javascript,dojo,dojo.gridx,jsonreststore,Javascript,Dojo,Dojo.gridx,Jsonreststore,我在想,我忽略了一些简单的事情——我离完成这项工作太近了 我有一个需要用服务器信息更新的网格 以下是它的工作方式: 用户选择一个项目 使用选定的项ID进行JsonRest查询 更新表格-显示与所选项目相关的注释 以下是网格的设置方式: 函数noteTabSetup{ var store = JsonRest({target:"//localhost/program/notes", idAttribute:"id"}); var structure = [{ field: 'id', name:

我在想,我忽略了一些简单的事情——我离完成这项工作太近了

我有一个需要用服务器信息更新的网格

以下是它的工作方式:

用户选择一个项目 使用选定的项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) {
-----------------------------------^
有什么想法吗?先谢谢你。 克里斯

感谢您的回复-这很有意义,store被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对象更新网格的好例子。谢谢。

,因为代码本身第一次替换了存储

grid.store.query({ find: "ByItem", item: itemId }).then(function(result) {
  grid.setStore(new ItemFileReadStore({data: {items : result}}));
});
在这里,网格的存储最初是JsonRest存储,在运行查询方法后,它被新的ItemFileReadStore对象替换。这里的错误是查询不是ItemFileReadStore的方法,而是传递给fetch方法的参数。请查看dojo文档中关于此的一些示例

另一方面,JsonRest存储具有方法查询。因此存在矛盾。如果需要ItemFileReadStore,请相应地更改代码

例如:-


啊,明白了。我宁愿只使用JsonRest,而不是ItemFileReadStore。我尝试过各种变体,但无法更新网格。
store.fetch( { query: { name: 'Ice cream' },  
               onItem: function(item) {
                  console.log( store.getValue( item, 'name' ) );
                  console.log( 'cost: ', store.getValue( item, 'cost' ) );
               }
});