【问题标题】:Asp.net MVC-2 with dojo带有道场的 Asp.net MVC-2
【发布时间】:2011-04-08 13:46:02
【问题描述】:

是否可以在 MVC-2 中使用 dojo(尤其是网格)?关于我们如何使用它的任何示例/想法?

【问题讨论】:

    标签: asp.net asp.net-mvc-2 dojo dojox.grid


    【解决方案1】:

    我没有看到 MVC2 和其他类型的应用程序之间的区别...

    你应该阅读dojo grid

    首先,您需要加载 dojo 脚本(最好在母版页上加载)。 您还可以使用以下方式添加一些 dojo 网格的 css 样式:

    Site.Master:

    <html>
       <head>
    ...
    <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/dojo.xd.js" djconfig="parseOnLoad: true"></script>
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dijit/themes/claro/claro.css" />
    <style type="text/css">
        @import "http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/grid/resources/Grid.css";
        @import "http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/grid/resources/claroGrid.css";
        .dojoxGrid table
        {
            margin: 0;
        }
        </style>
    ...
       </head>
    ....
    </html>
    

    之后你应该在视图中添加一些代码来初始化dojo网格,例如:

    索引.aspx:

    ...
    <script>
       dojo.require("dojox.grid.DataGrid");
       dojo.require("dojo.data.ItemFileReadStore");
       var layoutCountries = [
           [{
                    field: "abbr",
                    name: "Abbeviation",
                    width: 10
            },
            {
                field: "name",
                    name: "Name",
                    width: 10
            },
            {
                field: "capital",
                    name: "Capital",
                    width: 'auto'
            }]];
            var storeData = {
                identifier: 'abbr',
                label: 'name',
                items: [{
                    abbr: 'ec',
                    name: 'Ecuador',
                    capital: 'Quito'
                },
                    {
                        abbr: 'eg',
                        name: 'Egypt',
                        capital: 'Cairo'
                    },
                    {
                        abbr: 'sv',
                        name: 'El Salvador',
                        capital: 'San Salvador'
                    },
                    {
                        abbr: 'gq',
                        name: 'Equatorial Guinea',
                        capital: 'Malabo'
                    },
                    {
                        abbr: 'er',
                        name: 'Eritrea',
                        capital: 'Asmara'
                    },
                    {
                        abbr: 'ee',
                        name: 'Estonia',
                        capital: 'Tallinn'
                    },
                    {
                        abbr: 'et',
                        name: 'Ethiopia',
                        capital: 'Addis Ababa'
                    }]
            }
        </script>
    <div style="width: 400px; height: 300px;">
            <div dojotype="dojo.data.ItemFileReadStore" jsid="countryStoreForGrid" data="storeData">
            </div>
            <div id="grid" dojotype="dojox.grid.DataGrid" store="countryStoreForGrid" structure="layoutCountries"
                queryoptions="{deep:true}" query="{}" rowsperpage="40">
            </div>
        </div>
    ...
    

    而这段代码的结果是:

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-16
    • 2014-11-13
    • 2011-06-19
    • 2011-02-19
    • 1970-01-01
    • 1970-01-01
    • 2016-12-23
    • 1970-01-01
    相关资源
    最近更新 更多