0

选择帐户后,我想在 contactGrid 中显示所有相关联系人。我可以用 XhrGet 做到这一点,但我想使用 JsonRest。

这是我设置网格的方法:

function contactTabSetup() {
  var structure = [{ field: 'id', name: 'Id', width: '5em' },
                   { field: 'firstName', name: 'First Name', width: '12%' },
                   { field: 'lastName', name: 'Last Name', width: '12%' },
                   { field: 'email', name: 'Email', width: '12%' },
                   { field: 'description', name: 'Description' },
                   { field: 'mobileNumber', name: 'Mobile Phone', width: '12%' }];

  var contactGrid = new Grid({
    id: 'contactGrid',
    pageSize: 20,
    cacheClass: Cache,
    structure: structure,
    noDataMessage: "No contacts found",
    modules: [SingleSort]}, contactTab);

  contactGrid.startup();
}

这是我想要填充网格的方式:

function contactLoad(acctIds) {
  var grid = registry.byId("contactGrid");
  grid.model.clearCache();
  grid.setStore(JsonRest({target:"//localhost:8080/program/contacts/byAccount/" + acctIds}));
  grid.body.refresh();
}

正在返回正确的 Json 响应(在控制台上查看):

{
    "description": "Mike is a cool guy",
    "email": "mike@mike.net",
    "firstName": "Mike",
    "id": 1503,
    "lastName": "Smith",
    "mobileNumber": "555-555-5555"
}

...但我无法让网格显示新数据。

任何帮助,将不胜感激!谢谢


我尝试了许多其他方法,但没有成功……这就是我卡住的地方 - 不知道还能尝试什么。我进行 JsonRest 调用,取回 Json 对象,并将其打印到控制台。看到 json 响应看起来不错,我尝试 setStore 并抛出此错误:“s.query is not a function in dojo.js”(第 382 行)。这是一个错误,还是我错过了什么?谢谢你。

// s.query is not a function in dojo 10.0.1
grid.model.clearCache();
var store = new JsonRest({target:"//localhost:8080/program/contacts/byAccount"});
store.get(acctIds).then(function(items){
  console.log(items);
  grid.setStore(items);
});
grid.body.refresh();

我找到了。改变:

grid.setStore(items);

grid.setStore(new ItemFileReadStore({data: {items : result}}));

有谁知道如何只使用 JsonRest 而不包括 ItemFileReadStore?谢谢你,克里斯

4

1 回答 1

0

我的小建议是尝试设置一次存储并改用过滤器。

grid.filter({"acctId":"..."});

第二件事是 store 有时需要 idAttribute 定义,即

JsonRestStore({target:"...", idAttribute:"id"});
于 2014-07-17T17:03:08.003 回答