2014-09-11 52 views
0

我創建了一個道場gridcontainer像下面給出無法添加組件DojoX中/佈局/ GridContainer

<body class='claro'> 
<button onclick="add()"> Add </button> 
    <div id='border' data-dojo-type='dijit/layout/BorderContainer'> 
     <div id='grid'></div> 
    </div> 
    <script type='text/javascript'> 
    require(
     ['dojo/ready', 'dojo/parser', 'dojox/layout/GridContainer', 'dojox/widget/Portlet'], 
     function (ready, Parser, GridContainer, Portlet) { 
      ready(function() { 
       Parser.parse().then(function() { 
        // create grid and put into border container 
        var grid = new GridContainer({nbZones:3, id: 'gc'}, 'grid'); 

        // create cells and put into grid 
        for (var i = 0; i < 30; i++) { 
         grid.addChild(new Portlet({ 
          closable:false, 
          content:'(' + Math.floor(i/3) + ', ' + (i%3) + ')' 
         })); 
        } 
        grid.startup(); 
       }); 
      }); 
     }); 
    </script> 
</body> 

它工作正常,但是當我累加一個孩子,而點擊這個代碼

添加按鈕
<script type="text/javascript"> 
    function add() 
    { 
     var grid1 = dojo.byId("gc");  
     require(
      ['dojo/ready', 'dojo/parser', 'dojox/layout/GridContainer', 'dojox/widget/Portlet'], 
      function (Parser, GridContainer, Portlet) 
      { 
       grid1.addChild(new Portlet({ 
       closable:false, 
       content:'' 
      })); 
     }); 
    }; 
    </script> 

的意志帶給錯誤grid1.appendchild()是不是一個函數

有什麼錯呢?

回答

0

dojo.byId只能給你DOM對象,但GridContainer是一個dijit/widget。試試這個:

<script type="text/javascript"> 
    function add() 
    { 
     require(
      ['dojo/ready', 'dojo/parser', 'dojox/layout/GridContainer', 'dojox/widget/Portlet', 'dijit/registry'], 
      function (Parser, GridContainer, Portlet, dijit) 
      { 
       var grid1 = dijit.byId("gc");  
       grid1.addChild(new Portlet({ 
       closable:false, 
       content:'' 
      })); 
     }); 
    }; 
</script>