以编程方式创建Dojo DataGrid:“抱歉,发生错误”。布局问题? [英] Programmatically creating a Dojo DataGrid: "Sorry, an error occurred." Layout issue?

查看:190
本文介绍了以编程方式创建Dojo DataGrid:“抱歉,发生错误”。布局问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用从Web服务检索的一些数据创建DataGrid。经历了很多痛苦之后,我意识到问题不在于数据和服务。我能够以声明方式创建DataGrid,但是我需要以编程方式进行编写,因为我会在更复杂的场景中执行。

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.

我从一个复杂的用例到一个非常简单的,它仍然失败。
我看到的只是DataGrid,但经典的对不起,发生错误错误。

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         |
 |                                       |

这是我的简化示例:

<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.

任何建议?

推荐答案

问题是数据存储需要不同的格式:

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

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

解决问题。

这篇关于以编程方式创建Dojo DataGrid:“抱歉,发生错误”。布局问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆