2017-03-18 26 views
2

我有容器(ExtJS的4.2.2)無法獲取標籤,這不是積極

items: [{ 
      xtype: 'container', 
      layout: 'card', 
      flex: 1, 
      itemId: 'tab-container', 
      deferredRender: false, 
      items: [ { 
       xtype: 'panel', 
       layout: 'fit', 
       dockedItems: [routessearch], 
       items: [routes] 
      }, { 
       xtype: 'panel', 
       layout: 'fit', 
       forceLayout: true, 
       dockedItems: [routessearch], 
       items: [routesSubs] 
      }] 
     }] 

當頁面加載,我可以得到第一個標籤,因爲它已經是活動的。但我無法獲得第二個標籤,因爲它尚未創建。

我試圖使用deferredRender:false和forceLayout:true(如代碼示例中所示),但它不起作用。

+2

你究竟是什麼意思的「獲取標籤」,你可以發佈你的代碼? – pagep

+3

你可以創建小提琴來說明你的問題? –

+0

請添加您嘗試訪問secound選項卡的代碼。 –

回答

1

在ExtJs中,您應該直接與組件進行交互,而不是與dom進行交互。

所以,當你更換var elements = document.querySelectorAll(query);Ext.ComponentQuery.query(query);你得到的匹配組件的數組,你可以與他們進行互動。

Ext.ComponentQuery的煎茶文檔:

提供內Ext.ComponentManager (全局)或文檔上的特定Ext.container.Container與 類似的語法的CSS選擇組件的搜索。返回匹配的數組 組件或空數組。

因此,在組件查詢Ext.ComponentQuery.query('#tab-container > panel')後,你有所有的內部面板。 與second = components[1]你有第二個參考。 現在您可以與組件進行交互。
但是,如果您還需要訪問組件的dom,您可以通過second.getEl().dom獲取它。

所以完整的代碼看起來像。

Ext.create('Ext.container.Container', { 
    renderTo: Ext.getBody(), 
    width: 200, 
    height: 200, 
    layout: 'card', 
    itemId: 'tab-container', 
    deferredRender: false, 
    items: [{ 
     title: 'P1' 
    }, { 
     title: 'P2' 
    }], 
    listeners: { 
     boxready: function() { 
      var components = Ext.ComponentQuery.query('#tab-container > panel'); 
      var second = components[1]; 
      var el = second.getEl(); 
      var dom = el.dom; 
      // code to interact with the component or with the dom 
     } 
    } 
}); 

請參閱Sencha Fiddle中的代碼。