2013-03-23 88 views
0

里面我在道场newbe,我只创建一个布局的index.php有标签的容器和标签要求list.php的道场1.8网格选项卡

<!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?

回答

1

我要去移动从“你如何解决当前的问题”,并尝试回答“你如何满足您的要求”了。

要做到这一点,我假设你的网格内容最终将动态和按需交付。如果是这样,请将所有网格构建代码放入初始页面加载中,然后使用xhrGet仅提取数据以填充数据对象(但请参阅后面的段落以节省不必要的代码)。

数据应该从你的PHP代码交付作为一个JSON字符串化的对象(建立数组从PHP提供再使用json_encode(utf8_encode(data_array))

IIRC(它已经有一段时间),你应该只能够通过URL作为参数到服务网格,如果返回的数据是正确的格式,它应该加载,并自动显示它的数据对象

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

你会处以一exsmpl使用网格大约在中途停下来。如果你的意图是将数据发送回服务器,或者让它在客户端更改,你可能需要使用itemFileWriteSore。我个人一直习惯使用它,以防万一我需要它。开销很小。

如果你的代码很可能要重新读取数据网格在页面加载后,则需要通过一对夫妇更跳火圈,但它仍然是相当容易的事情。

警告..我在想Zend 1.11,dojo 1.4这里的术语......但是原理将会是一样的......它的基本原理是dojo,所以我怀疑他们已经改变了对象数据存储那么多:)

+0

我想做一个后端。在未来,我需要一个负载从MySQL服务器保存,但现在还不是问题 我的问题是我怎么能构建一个程序。我在这个后端有不同的部分来管理各种数据库对象。这个对象有一个列表和带有制表符的编辑元素表单。 我的想法是加载任何部分的文件,例如:contacts.php。在这个文件中,当我选择这些元素之一时,我想将这些联系人列表的代码和编辑一个元素的窗体放在一起。 这不是有效的方法吗?你如何做到这一点?你知道一个网站来说明如何构建一个道场网站? – David 2013-03-23 16:51:51

+0

这是一个比原始程序范围更广泛的问题。我担心我所做的一切都是通过做和改进我的技术来完成的,所以我对推荐教程网站没有多大用处,但dojo文档(http://dojotoolkit.org/documentation/)非常好,网站是充满教程和例子。我建议你从那里开始并向外工作。 – Radiotrib 2013-03-23 21:59:20

+0

David - 查看list.php - 从objectStore的定义开始。您可以使用本地生成的数据填充存储区,但使用itemFileWriteStore时,可以指定一个URL而不是原始数据。对于测试,该网址可能只是一个包含由商店检索的预定义json的文本文件。商店将通过调用url来获取数据。在开发过程中,你可以通过调用一个能够动态生成json的php文件来取代对json文件的调用......我希望这是有道理的,有时候我的解释有点困惑。 – Radiotrib 2013-03-24 13:36:12