gpt4 book ai didi

javascript - QueryReadStore 将 JSON 加载到 DataGrid 中,但 JsonRestStore 不会(来自同一来源)

转载 作者:行者123 更新时间:2023-11-29 16:29:04 24 4
gpt4 key购买 nike

我正在根据 REST 接口(interface)提供的 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 接口(interface)获取 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}]}

有什么想法吗?谢谢。

最佳答案

要使用 JsonRestStore,您的响应必须只是您提供的示例中的项目部分:

[{"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 - QueryReadStore 将 JSON 加载到 DataGrid 中,但 JsonRestStore 不会(来自同一来源),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2444801/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com