以编程方式创建 Dojo DataGrid:“抱歉,发生错误。”布局问题?

发布于 2024-11-29 08:45:33 字数 1572 浏览 0 评论 0原文

我正在尝试使用从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小霸王臭丫头 2024-12-06 08:45:33

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

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

这解决了问题。

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

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

That solves the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文