0

我是 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 网格不显示,我该怎么做呢?为什么是原因,没有没有javascript执行?

4

1 回答 1

1

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

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

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

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

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

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

如果您的代码可能希望在页面加载后重新读取网格数据,那么您将需要再跳几圈,但这仍然很容易做到。

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

于 2013-03-23T15:24:26.353 回答