2014-03-31 72 views
1

我在Dojo中遇到了一些困難。我正在嘗試構建一個包含dgrid的小部件。何時調用DGrid.startup() - 調用過早導致渲染效果不佳

的dgrid呈現這樣的:

enter image description here

調整瀏覽器窗口後,一切都很好,它顯示是這樣的:

enter image description here

我認爲這個問題我運行進入與調用grid.startup()函數太早有關。當我將通話延遲10秒鐘(請參閱註釋部分代碼)時,所有內容均按預期工作。

這是我的代碼:

define([ 
     // ... 
    ], 
    function(
     // ... 
    ) { 
     return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin] ,{ 
      templateString: template, 

      startup: function(){ 

       this.inherited(arguments); 
       var store = new Memory({data: this.someArray}); 
       var grid = new (declare([OnDemandGrid, DijitRegistry]))({ 
        store: store, 
        columns: { 
         name: "Name column" 
        } 
       }, this.gridDiv); 

       // If I wrap startup in this - everything is fine. 
       // window.setInterval(function(){ 
       grid.startup(); 
       // }, 1000*10); 
      } 
     }); 
    } 
); 

這是我使用的模板:

<div style="height:100%"> 
    <table border="1"> 
     <tr> 
      <td> 
       <button data-dojo-attach-point="addBtn" data-dojo-type="dijit/form/Button">Add item</button> 
       <div data-dojo-attach-point="gridDiv"></div> 

      </td> 
      <td> 
       Insert Summary here. 
      </td> 
     </tr> 
    </table> 
</div> 

問:這到底是怎麼回事?我應該在哪裏給dgrid打電話啓動?

回答

0

正如預期的那樣,問題在於調用啓動方法太早 - 但是小部件本身沒有問題。

遇到的問題是與父窗口小部件。父窗口小部件(TabContainer)沒有正確啓動。這是父控件是如何工作的:

  1. 創建新TabContainer的:var tc = new TabContainer({...});
  2. 創建新的contentPane:var cp1 = new ContentPane({content: <the above widget>, ...});
  3. 添加的contentPane到TabContainer的:在TabContainer的tc.addChild(cp1);
  4. 呼叫啓動:tc.startup();

更改順序爲此,解決了問題:

在TabContainer的 var tc = new TabContainer({...});
  • 啓動電話:
    1. 創建新TabContainer的tc.startup();
    2. 創建新的contentPane:var cp1 = new ContentPane({content: <the above widget>, ...});
    3. 添加到contentPane的TabContainer的:tc.addChild(cp1);
  • 相關問題