我有以下问题。我的REST Web服务像这样返回json:
{ “响应”:{ “报头”: “”, “项目”:{ “项”:[{ “@ ID”: “1”, “电子邮件”: “管理员@管理员”, “姓名”: “管理员”, “姓氏”: “管理”, “登录”: “管理员”},{ “@ ID”: “2”, “电子邮件”: “Bennett@Tawney.com”, “名字”: “内特” , “姓氏”: “托尼”, “登录”: “bennettabcd”} ...
如何强制DataGrid显示上面json的项目?我无法更改REST Web服务,它必须以这种格式返回jsons。 Http请求没问题,服务器返回我的json,但是数据网格没有填写。你有什么想法吗?
我的“dojo”代码如下:
var store = new Cache(new JsonRest({ target: settings.vars.API_URL + "/frapi/users/load", start: page * rows, count: 10, sort: [ {attribute: "id", descending: true} ], headers: { "Content-Type": "application/json" } }), Memory()); grid = new DataGrid({ store: new ObjectStore({objectStore: store}), queryOptions: {}, structure:[{ defaultCell: { width: "auto" }, cells: [ {name: "Id", field: "id", width: "50px"}, {name: "Login", field: "login"}, {name: "Email", field: "email", width: "200px"}, {name: "Firstname", field: "firstname"}, {name: "Lastname", field: "lastname"} ] }] }, "grid"); grid.startup();
提前致谢
答案 0 :(得分:1)
好的,我找到了解决方案。请参阅以下代码:
var extractItemsFromResponse = function(deferred) { return deferred.then(function(response) { return response.response.items.item; }); }; aspect.after(store, "query", extractItemsFromResponse);
我希望它会对你有所帮助。