使用 XHR 创建 DataGrid 的问题
我正在尝试使用 XHR 构建一个 DataGrid,但是网格没有正确创建,我看到了很多例子,并根据我在互联网上找到的内容做了我的操作,但没有成功......
我做错了什么?
我的道场:
var a = dojo.xhrGet({
url : "/dojo/pix/StatusXml",
handlesAs: "xml",
preventCache: true,
headers: { "Content-Type": "application/x-www-form-urlencoded"},
// mimetype: "application/xml"
});
a.addCallback(function(myXml) {
var grid = dijit.byId("grid");
// var gridStore = new dojo.data.ItemFileReadStore({data:{items: myXml} });
var gridStore = new dojo.data.ItemFileWriteStore({data:{items: myXml} });
alert("myxml: \n"+ myXml +" \n gridStore: \n"+gridStore);
grid.setStore(gridStore);
grid.refresh();
});
Gid 出现的消息中的结果是“抱歉,发生错误” 在此处输入链接说明
I'm trying to build a DataGrid using XHR, but the Grid is not being created correctly, I saw many examples and did my based on what I found on the internet but without success ...
what am I doing wrong?
my dojo:
var a = dojo.xhrGet({
url : "/dojo/pix/StatusXml",
handlesAs: "xml",
preventCache: true,
headers: { "Content-Type": "application/x-www-form-urlencoded"},
// mimetype: "application/xml"
});
a.addCallback(function(myXml) {
var grid = dijit.byId("grid");
// var gridStore = new dojo.data.ItemFileReadStore({data:{items: myXml} });
var gridStore = new dojo.data.ItemFileWriteStore({data:{items: myXml} });
alert("myxml: \n"+ myXml +" \n gridStore: \n"+gridStore);
grid.setStore(gridStore);
grid.refresh();
});
Gid the result in the message that appears is "sorry, an error occurred"
enter link description here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果使用
xml
作为dojo.xhrGet
函数的handleAs
值,响应数据将被转换为XML DOM对象。但是 dojo.data.ItemFileReadStore 期望获取 JSON 对象作为数据格式。因此,您可以使用
dojox.data.XmlStore
作为网格的存储,也可以手动将 XML DOM 对象转换为 JSON 数据。实际上这里不需要使用XHR,因为dojo.data.ItemFileReadStore
和dojox.data.XmlStore
可以使用URL作为数据源,并且它们将处理数据检索。If you use
xml
as thehandleAs
value ofdojo.xhrGet
function, the response data will be converted to a XML DOM object. Butdojo.data.ItemFileReadStore
is expecting to get a JSON object as the data format.So you can either use
dojox.data.XmlStore
as the grid's store or convert the XML DOM object to JSON data manually. Actually it's not required to use XHR here, becausedojo.data.ItemFileReadStore
anddojox.data.XmlStore
can use URL as the data source and they will handle the data retrieve.dojox.data.XmlStore 不通过 XMLRequest 从 servlet 检索数据...仅从文件中检索数据
dojox.data.XmlStore not retrieve data from the servlet by XMLRequest ... only data from a file