javascript - 如何显示我的 GridX

标签 javascript web-applications dojo dojo.gridx

我没有成功地显示我的 GridX。我目前在 firebug 中收到 4 个与 dojo.js 有关的错误,其中两个 Error: scriptError 一个 Error: multipleDefine 和一个奇怪的错误: GET https://本地主机:8443/warfile/javascript/dojo-release-1.10.0/dojo/store/templates/Grid.html 404 未找到

我正在尝试遵循此poorly documented example from the Gridx wiki

这是我的代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Test GridX Widget</title>

    <script type="text/javascript" src="javascript/dojo-release-1.10.0/dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: true" ></script>
    <script type="text/javascript" src="javascript/gridx-1.3/Grid.js"></script>
    <script type="text/javascript" src="javascript/gridx-1.3/GridCommon.js"></script>

    <link rel="stylesheet" href="javascript/dojo-release-1.10.0/dijit/themes/claro/claro.css" />
    <link rel="stylesheet" href="javascript/dojo-release-1.10.0/dijit/themes/claro/document.css" />
    <link rel="stylesheet" href="javascript/gridx-1.3/resources/claro/Gridx.css" />
    <style type="text/css">
    .gridx {
        width: 400px;
        height: 200px;
    }
    </style>

<script>
    require([
             //Require resources.
             "dojo/store/Memory",
             "gridx/core/model/cache/Sync",
             "gridx/Grid"
         ], function(Memory, Cache, Grid){

        //Use dojo/store/Memory here
        var store = new Memory({
            data: [
                { id: 1, name: 'John', score: 130, city: 'New York', birthday: '1980/2/5'},
                { id: 2, name: 'Alice', score: 123, city: 'Washington', birthday: '1984/3/7'},
                { id: 3, name: 'Lee', score: 149, city: 'Shanghai', birthday: '1986/10/8'},
                { id: 4, name: 'Mike', score: 100, city: 'London', birthday: '1988/8/12'},
                { id: 5, name: 'Tom', score: 89, city: 'San Francisco', birthday: '1990/1/21'}
            ]
        });

        //We are using Memory store, so everything is synchronous.
        var cacheClass = "gridx/core/model/cache/Sync";

        var structure = [
                         { id: 'name', field: 'name', name: 'Name', width: '50px'},
                         { id: 'city', field: 'city', name: 'City'},
                         { id: 'score', field: 'score', name: 'Score', width: '80px'}
                     ];

             //Create grid widget.
             var grid = Grid({
                 id: 'grid',
                 cacheClass: Cache,
                 store: store,
                 structure: structure
             });

             //Put it into the DOM tree. Let's assume there's a node with id "gridContainer".
             grid.placeAt('gridContainer');

             //Start it up.
             grid.startup();
         });
</script>

</head>
<body class="claro">
    <div id="gridContainer"></div>
</body>
</html>

最佳答案

这是 GridX 的工作代码。

<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>GridX testing</title>

    <style type="text/css">
        /*Use claro theme.*/
        @import "javascript/dojo-release-1.10.0/dijit/themes/claro/claro.css";
        @import "javascript/dojo-release-1.10.0/dijit/themes/claro/document.css";

        /*Import the main CSS file of Gridx.*/
        @import "javascript/dojo-release-1.10.0/gridx-1.3/resources/claro/Gridx.css";

        .gridx {
            width: 400px;
            height: 200px;
        }
    </style>


    <!-- dojo configuration options -->
    <!-- For Package configuration refer tutorial at       http://dojotoolkit.org/documentation/tutorials/1.7/modules/ -->
    <script type="text/javascript">
        var dojoConfig = {
            async: true,
            baseUrl: "/javascript/",
            tlmSiblingOfDojo: false,
            packages: [
                { name: "dojo",  location: "dojo-release-1.10.0/dojo" },
                { name: "dijit", location: "dojo-release-1.10.0/dijit" },
                { name: "dojox", location: "dojo-release-1.10.0/dojox" },
                { name: "gridx", location: "dojo-release-1.10.0/gridx-1.3" }
            ]
        };
    </script>
    <!-- third-party javascript -->
    <script src="javascript/dojo-release-1.10.0/dojo/dojo.js"></script>

    <script>
        require([
            //Require resources.
            "dojo/store/Memory",
            "gridx/core/model/cache/Sync",
            "gridx/Grid"
        ], function(Memory, Cache, Grid){

            //create store......
            var store = new Memory({
                data: [
                    { id: 1, name: 'John', score: 130, city: 'New York', birthday: '1980/2/5'},
                    { id: 2, name: 'Alice', score: 123, city: 'Washington', birthday: '1984/3/7'},
                    { id: 3, name: 'Lee', score: 149, city: 'Shanghai', birthday: '1986/10/8'},
                    { id: 4, name: 'Mike', score: 100, city: 'London', birthday: '1988/8/12'},
                    { id: 5, name: 'Tom', score: 89, city: 'San Francisco', birthday: '1990/1/21'}
                ]
            });

            //create structure......
            var structure = [
                { id: 'name', field: 'name', name: 'Name', width: '50px'},
                { id: 'city', field: 'city', name: 'City'},
                { id: 'score', field: 'score', name: 'Score', width: '80px'}
            ];


            //Create grid widget.
            var grid = Grid({
                id: 'grid',
                cacheClass: Cache,
                store: store,
                structure: structure
            });

            //Put it into the DOM tree. Let's assume there's a node with id "gridContainer".
            grid.placeAt('gridContainer');

            //Start it up.
            grid.startup();
        });

    </script>
</head>
<body class="claro">
    <div id="gridContainer"></div>
</body>
</html>

关于javascript - 如何显示我的 GridX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26284685/

相关文章:

javascript - 在 dojo 中动态填充 ComboBox

javascript - 使用 Post 数据 (json) 重定向并具有 header

javascript - 每秒获取 div 中的图像 ID

javascript - 我试图在谁赢谁输的答案弹出之前延迟(剪刀石头布游戏)

javascript - 使用 map 调整 IP 命中计数器的大小

iphone - 是否有 iPhone url 方案可以从链接以独立模式启动 Web 应用程序

web-applications - 更改 Google 帐户选择器显示的域

web-applications - 构建数据库驱动的 Web 应用程序

tabs - Dijit TabContainer 小部件图标

javascript - 在哪里可以找到 dojo 工具包 dijit 小部件的图标图像列表?