以编程方式创建 Dojo DataGrid:“抱歉,发生错误。”布局问题?
我正在尝试使用从 Web 服务检索到的一些数据创建 DataGrid。经过一番痛苦之后,我意识到问题不在于数据,也不在于服务。我能够以声明方式创建 DataGrid,但我需要以编程方式执行此操作,因为我将在更复杂的场景中执行此操作。
我从一个复杂的用例变成了一个非常简单的用例,但它仍然失败。 我看到的只是 DataGrid,但出现了经典的“抱歉,发生错误”错误。
+----------+----------------------------+
| id | name |
+----------+----------------------------+
| Sorry, an error occurred |
| |
这是我的简化示例:
<html>
<head>
<link rel="stylesheet" href="MyCSS.css">
<script type="text/javascript" src="lib/dojo/dojo.js" charset="utf-8"></script>
<script>
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojox.grid.DataGrid");
</script>
</head>
<body class="soria">
<div id="node" style="width:650px;height:300px"></div>
<script>
var structure = [
{field: "id", width: 20},
{field: "name", width: 100}
];
var data = [
{"id": 1, "name": "John"},
{"id": 2, "name": "Lucy"}
];
var node = dojo.byId("node");
var store = new dojo.data.ItemFileReadStore({
data: data
});
var grid = new dojox.grid.DataGrid({
store: store,
structure: structure
},
document.createElement('div'));
node.appendChild(grid.domNode);
grid.startup();
</script>
</body>
</html>
我希望我错过了一些非常愚蠢的东西。控制台不显示错误。
有什么建议吗?
I'm attempting to create a DataGrid with some data retrieved from a Web Service. After a lot of suffering I realized the problem is not in the data nor in the service. I was able to create the DataGrid declaratively, but I need to do it programmatically, since I will be doing it in more complex scenarios.
I went from a complex use case to a very simple one and it's still failing.
What I'm seeing is just the DataGrid, but with the classic "Sorry, an error occurred" error.
+----------+----------------------------+
| id | name |
+----------+----------------------------+
| Sorry, an error occurred |
| |
This is my simplified example:
<html>
<head>
<link rel="stylesheet" href="MyCSS.css">
<script type="text/javascript" src="lib/dojo/dojo.js" charset="utf-8"></script>
<script>
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojox.grid.DataGrid");
</script>
</head>
<body class="soria">
<div id="node" style="width:650px;height:300px"></div>
<script>
var structure = [
{field: "id", width: 20},
{field: "name", width: 100}
];
var data = [
{"id": 1, "name": "John"},
{"id": 2, "name": "Lucy"}
];
var node = dojo.byId("node");
var store = new dojo.data.ItemFileReadStore({
data: data
});
var grid = new dojox.grid.DataGrid({
store: store,
structure: structure
},
document.createElement('div'));
node.appendChild(grid.domNode);
grid.startup();
</script>
</body>
</html>
I'm hoping I'm missing something really dumb. The console doesn't show errors.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是数据存储需要不同的格式:
这解决了问题。
The problem is that the data store requires a different format:
That solves the problem.