Programmatically creating a Dojo DataGrid: “Sorry, an error occurred.” Layout issue?

喜夏-厌秋 提交于 2019-12-11 07:41:57

问题


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?


回答1:


The problem is that the data store requires a different format:

 var store = new dojo.data.ItemFileReadStore({
  data: {items: data}
 });

That solves the problem.



来源:https://stackoverflow.com/questions/7054546/programmatically-creating-a-dojo-datagrid-sorry-an-error-occurred-layout-is

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!