0

我在想我忽略了一些简单的事情——我非常接近完成这项工作。:)

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

这是它应该工作的方式:

  1. 用户选择一个项目
  2. 使用选定的项目 ID 进行 JsonRest 查询
  3. 更新网格 - 显示与所选项目相关的注释

以下是网格的设置方式:

函数 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 对象更新网格的好例子。谢谢你。

4

1 回答 1

0

因为代码本身第一次替换了store。

grid.store.query({ find: "ByItem", item: itemId }).then(function(result) {
  grid.setStore(new ItemFileReadStore({data: {items : result}}));
});

在这里,网格的存储最初是 JsonRest 存储,在运行查询方法之后,它被新的 ItemFileReadStore 对象替换。这里的错误是“query”不是ItemFileReadStore的方法,而是传递给“fetch”方法的参数。查看 dojo 文档中的一些示例。

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

例如:-

store.fetch( { query: { name: 'Ice cream' },  
               onItem: function(item) {
                  console.log( store.getValue( item, 'name' ) );
                  console.log( 'cost: ', store.getValue( item, 'cost' ) );
               }
});
于 2014-08-08T19:13:45.707 回答