【问题标题】:Dojo 1.8 grid inside tab选项卡内的 Dojo 1.8 网格
【发布时间】:2013-03-23 14:40:45
【问题描述】:

我是 Dojo 的新手,我只是创建了一个带有标签容器的布局 index.php 和一个标签调用 list.php

<!DOCTYPE HTML>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Demo: Progammatic Layout</title>

        <link rel="stylesheet" href="style.css" media="screen">
        <link rel="stylesheet" href="js/dijit/themes/claro/claro.css" media="screen">
                 <link rel="stylesheet" href="js/dojox/grid/resources/claroGrid.css" media="screen">
    </head>
    <body class="claro">
        <div id="appLayout" class="demoLayout"></div>
        <!-- load dojo and provide config via data attribute -->
        <script src="js/dojo/dojo.js"></script>
        <script>
            require(["dijit/layout/BorderContainer", 
                 "dijit/layout/TabContainer", 
                 "dijit/layout/ContentPane", 
                 "dijit/layout/AccordionContainer",
                 "dijit/layout/AccordionPane",
                 "dojox/grid/DataGrid",
                 "dojox/grid/cells",
                 "dojo/ready", 

                 ],
            function(BorderContainer, TabContainer,ContentPane, AccordionContainer, AccordionPane, DataGrid, gridCells, ready){
                ready(function(){
                    // create the BorderContainer and attach it to our appLayout div
                    var appLayout = new BorderContainer({
                        design: "headline"
                    }, "appLayout");


                    // create the TabContainer
                    var contentTabs = new TabContainer({
                        region: "center",
                        id: "contentTabs",
                        tabPosition: "bottom",
                        "class": "centerPanel"
                    });

                    // add the TabContainer as a child of the BorderContainer
                    appLayout.addChild( contentTabs );

                    // create and add the BorderContainer edge regions
                    var header= new ContentPane({
                        region: "top",
                        "class": "edgePanel",
                        content: "Header content (top)",
                        splitter: true
                    });



                    /* Menú */
                    var contentMenu = new ContentPane({
                        region: "left",
                        id: "leftCol", 
                        "class": "edgePanel",
                        content: "",
                        padding:0,
                        splitter: true
                    });

                    var aContainer=new AccordionContainer({style:"height: 300px"}, "markup");
                        aContainer.addChild(new ContentPane({
                            title: "Contact",
                            content: "Hi!"
                        }));
                        aContainer.addChild(new ContentPane({
                            title:"Work",
                            content:"Hi how are you?"
                        }));
                    contentMenu.addChild(aContainer);



                    **var tabs=new ContentPane({
                        href: "list.php",
                        title: "Lista"
                    });**
                    contentTabs.addChild(tabs);



                    appLayout.addChild(header);
                    appLayout.addChild(contentMenu);

                    appLayout.addChild(contentTabs);






                      //aContainer.startup();
                    /*contentAcordion= new AccordionContainer({
                        min-size:20,
                        region:'leading,
                        splitter:true,
                        id:'leftAccordion'
                    });*/

                    // start up and do layout
                    appLayout.startup();










                    var cells = [
                      [
                        new gridCells.RowIndex({ width: "10%" }),
                        { name: "Column 1", field: "col1", width: "30%" },
                        { name: "Column 2", field: "col2", width: "30%" },
                        { name: "Column 3", field: "col3", width: "30%" }
                      ]
                    ];

                    gridLayout = [{
                            type: "dojox.grid._CheckBoxSelector"
                        }, 
                        cells
                    ];

                    var data = [
                        { id: 0, col1: "normal", col2: false, col3: "new", col4: "But are not followed by two hexadecimal"},
                        { id: 1, col1: "important", col2: false, col3: "new", col4: "Because a % sign always indicates"},
                        { id: 2, col1: "important", col2: false, col3: "read", col4: "Signs can be selectively"},
                        { id: 3, col1: "note", col2: false, col3: "read", col4: "However the reserved characters"},
                        { id: 4, col1: "normal", col2: false, col3: "replied", col4: "It is therefore necessary"},
                        { id: 5, col1: "important", col2: false, col3: "replied", col4: "To problems of corruption by"},
                        { id: 6, col1: "note", col2: false, col3: "replied", col4: "Which would simply be awkward in"}
                    ];

                    var grid = new DataGrid({
                    //store: test_store,
                    structure: cells,
                    rowSelector: "20px",
                    "class": "grid"
                    }, "grid");
                    grid.startup();
                });
            });
        </script>
    </body>
</html>

它运行成功,并加载了一个list.php。

在 list.php 我有一个创建网格的代码,如果我单独执行它可以工作并成功显示网格:

<!DOCTYPE HTML>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Demo: Progammatic Layout</title>

        <link rel="stylesheet" href="style.css" media="screen">
        <link rel="stylesheet" href="js/dijit/themes/claro/claro.css" media="screen">
                 <link rel="stylesheet" href="js/dojox/grid/resources/claroGrid.css" media="screen">
    </head>
    <body class="claro">
        <div id="grid" class="demoLayout"></div>

        <!-- load dojo and provide config via data attribute -->
        <script src="js/dojo/dojo.js"></script>
        <script>
            require([
                "dojox/grid/DataGrid",
                "dojox/grid/cells",
                "dojo/store/Memory",
                "dojo/data/ObjectStore",
                "dojo/_base/array",
                "dojo/_base/lang",
                "dojox/grid/_CheckBoxSelector",
                "dojo/domReady!"
            ], function(DataGrid, gridCells, Memory, ObjectStore, baseArray, lang, _CheckBoxSelector){
                var cells = [
                    [
                        new gridCells.RowIndex({ width: "10%" }),
                        { name: "Column 1", field: "col1", width: "30%" },
                        { name: "Column 2", field: "col2", width: "30%" },
                        { name: "Column 3", field: "col3", width: "30%" }
                    ],[
                        { name: "Column 4", field: "col4", colSpan: 4 }
                    ]
                ];

                gridLayout = [{
                    // First, our view using the _CheckBoxSelector custom type
                        type: "dojox.grid._CheckBoxSelector"
                    }, 
                    cells
                ];

                var data = [
                    { id: 0, col1: "normal", col2: false, col3: "new", col4: "But are not followed by two hexadecimal"},
                    { id: 1, col1: "important", col2: false, col3: "new", col4: "Because a % sign always indicates"},
                    { id: 2, col1: "important", col2: false, col3: "read", col4: "Signs can be selectively"},
                    { id: 3, col1: "note", col2: false, col3: "read", col4: "However the reserved characters"},
                    { id: 4, col1: "normal", col2: false, col3: "replied", col4: "It is therefore necessary"},
                    { id: 5, col1: "important", col2: false, col3: "replied", col4: "To problems of corruption by"},
                    { id: 6, col1: "note", col2: false, col3: "replied", col4: "Which would simply be awkward in"}
                ];

                var objectStore = new Memory({data:data});

                var test_store = new ObjectStore({objectStore: objectStore});

                // create the grids.
                var grid = new DataGrid({
                    store: test_store,
                    structure: cells,
                    rowSelector: "20px",
                    "class": "grid"
                }, "grid");
                grid.startup();

            });
        </script>
    </body>
</html>

但是如果我调用 index.php 网格不显示,我该怎么做?是什么原因,no no no javascript execute?

【问题讨论】:

    标签: javascript dojo dojox.grid.datagrid dojox.grid


    【解决方案1】:

    我将摆脱“您如何解决当前问题”并尝试回答“您如何满足您的要求”。

    为此,我假设您的网格内容最终将是动态的并按需交付。如果是这种情况,请将所有网格构建代码放入初始页面加载中,并使用 xhrGet 仅获取数据以填充数据对象(但请参阅后面的段落以节省不必要的编码)。

    数据应该从您的 php 代码作为 json 字符串化对象传递(构建数组以从 php 传递,然后使用 json_encode(utf8_encode(data_array))

    IIRC(已经有一段时间了)您应该能够将 url 作为参数传递给为网格提供服务的数据对象,如果返回的数据格式正确,它应该会自动加载并显示它。

    看看 itemFileReadStore - dojotoolkit.org/reference-guide/1.8/dojo/data/ItemFileReadStore.html

    您可以使用网格在页面的一半左右进行示例。如果您的意图是将数据发送回服务器或以某种方式允许在客户端中对其进行更改,则您可能希望改用 itemFileWriteSore。就个人而言,我一直习惯使用它,以防万一我需要它。开销很小。

    如果您的代码可能想要在页面加载后重新读取网格化数据,那么您将需要多跳几圈,但这仍然相当容易。

    Caveat .. 我在想 Zend 1.11,dojo 1.4 术语在这里......但原则将是相同的......它是 dojo 的基础,所以我怀疑他们已经改变了对象数据存储这么多: )

    【讨论】:

    • 我正在尝试做一个后端。将来我将需要从 MySQL 服务器加载保存,但现在这不是问题我的问题是如何构建程序。我在这个后端有不同的部分来管理各种数据库对象。这个对象有一个列表和带有标签的编辑元素表单。我的想法是为任何部分加载一个文件,例如:contacts.php。在这个文件中,当我选择其中一个元素时,我想放置此联系人列表的代码和编辑一个元素的表单。这不是有效的方式吗?你怎么做的?你知道一个网站来说明一个道场网站的结构吗?
    • 这是一个超出原始程序范围的更广泛的问题。恐怕我所学习的一切都是通过这样做和改进我的技术而发生的,所以我不太用于推荐教程网站,但是 dojo 文档 (dojotoolkit.org/documentation) 非常好,并且该网站充满了教程和示例。我建议你从那里开始向外工作。
    • David - 查看 list.php - 从 objectStore 的定义开始。您使用本地生成的数据来填充存储,但使用 itemFileWriteStore,可以指定 URL 而不是原始数据。对于测试,url 可以只是一个包含预定义 json 的文本文件,该文件由商店检索。商店将通过调用 url 来获取数据。在开发的后期,您可以将对 json 文件的调用替换为对动态生成 json 的 php 文件的调用......我希望这是有道理的,有时我的解释有点混乱。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 1970-01-01
    • 2017-10-21
    相关资源
    最近更新 更多