【发布时间】:2011-01-27 12:54:53
【问题描述】:
我正在从我的 REST 接口提供的 JSON 数据构建一个 Dojo DataGrid。 DataGrid 使用 QueryReadStore 很好地加载数据,但似乎不适用于通过管道传输到 JsonRestStore 的相同数据。
我在 Dojo 1.4.1 中使用以下 Dojo 库:
dojo.require("dojox.data.JsonRestStore");
dojo.require("dojox.grid.DataGrid");
dojo.require("dojox.data.QueryReadStore");
dojo.require("dojo.parser");
我通过以下方式声明我的商店:
var storeJRS = new dojox.data.JsonRestStore({target:"api/collaborations.php/1"});
var storeQRS = new dojox.data.QueryReadStore({url:"api/collaborations.php/1", requestMethod:"get"});
我这样创建网格布局:
var gridLayout = [
new dojox.grid.cells.RowIndex({ name: "Row #", width: 5, styles: "text-align: left;" }),
{
name: "Name",
field: "name",
styles: "text-align:right;",
width:20
},
{
name: "Description",
field: "description",
width:30
}
];
我按如下方式创建我的 DataGrid:<div dojoType="dojox.grid.DataGrid" jsid="grid2" store="storeQRS" structure="gridLayout" style="height:500px; width:1000px;"></div>
上述方法有效,但如果我使用 QueryReadStore 作为我的存储,则使用标题(名称、描述)创建网格,但它没有填充任何行:<div dojoType="dojox.grid.DataGrid" jsid="grid3" store="storeQRS" structure="gridLayout" style="height:500px; width:1000px;"></div>
使用 FireBug,我可以看到 QueryReadStore 正在从我的 REST 接口获取我的 JSON 数据。如下所示:
{"numRows":6,"items":[{"name":"My Super Cool Collab","description":"This is for all the super cool people in the super cool group","id":1},{"name":"My Other Super Cool","description":"This is for all the other super cool people","id":3},{"name":"This is another coll","description":"This is just some other collab","id":4},{"name":"some new collab","description":"this is a new collab","id":5},{"name":"yet another new coll","description":"uh huh","id":6},{"name":"asdf","description":"asdf","id":7}]}
有什么想法吗?谢谢。
【问题讨论】:
标签: javascript rest datagrid dojo datastore