gpt4 book ai didi

javascript - 如何使用 DOJO 从服务器读取 JSON 响应?

转载 作者:行者123 更新时间:2023-11-28 21:13:24 25 4
gpt4 key购买 nike

我在从服务器获取一些数据并用它填充数据存储时遇到一些问题:

这是我在 Display.jsp 页面中的脚本代码:

dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileReadStore");

dojo.addOnLoad(function() {

// our test data store for this example:
dojo.xhrGet({
url: "jsonAction.action",// this line can call the action in struts2. I had tested it !
handleAs: "json",
preventCache: true,
load: function(response, ioArgs){
//dojo.byId("replace").innerHTML = response;
// I can get json data by changing handleAs:"text"
//return response; //
}
});

var jsonStore = new dojo.data.ItemFileReadStore({
//??? how can I get the json data?
});

我想稍后使用此数据来填充 dojox.grid.DataGrid

我正在使用 Struts2、Hibernate、Tomcat 6

最佳答案

不要使用dojo.xhrGetdojo.data.ItemFileReadStore 有一个参数url,您可以在其中指定数据源。这是一个网格示例:

var sampleGrid = new dojox.grid.DataGrid({
store: new dojo.data.ItemFileReadStore({
url: "JSON_source",
clearOnClose: true,
urlPreventCache: true
}),
structure: [
{cells:
[[
{field: "JSON_field", name: "displayed value"},
...
]]
}
],
...
});

关于javascript - 如何使用 DOJO 从服务器读取 JSON 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8181947/

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