[英]How can I read a JSON reponse from server using DOJO?
我在從服務器獲取一些數據並用它填充數據存儲時遇到了一些麻煩:
這是我在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.xhrGet
。 dojo.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"},
...
]]
}
],
...
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.