2016-02-25 68 views
0

的第二標籤,同時訪問一個tabpanel的第二選項卡的網格行我m到處未定義的值。訪問一個tabpanel

我已經創建了下面的代碼一個tabpanel:

xtype: 'tabpanel', 
border: false, 
deferredRender: true, 
region: 'center', 
activeTab: 0, 
items:[{ 
     id: 'availableoperators', 
     itemId: 'ops-operators-grid', 
     xtype: 'chat.dashboard.opsmall', 
     title: 'Operators', 
     region: 'center' 
    }, { 
     id: 'availableagents', 
     itemId: 'ops-agents-grid', 
     xtype: 'chat.dashboard.opsmgrid', 
     title: 'Agents', 
     region: 'center' 
    }] 

這裏我米試圖訪問第二板行:

var opsGrid = Ext.getCmp('availableagents'); 
var records = opsGrid.store.getRange(0, opsGrid.store.getTotalCount()); 
for(var i = 0; i < records.length; i++) { 
    var row = opsGrid.getView().getRow(i); 
} 

上面的代碼工作正常,只有當我使用的ID第一個標籤。任何幫助,將不勝感激。

回答

1

它發生,因爲標籤上部件將在第一示出被渲染。默認情況下,將在此選項卡上呈現網格之後加載。因此,您沒有呈現標記(opsGrid.getView()),並且沒有在存儲中加載數據,直到您打開選項卡。如果你打開第二個標籤並手動運行你的代碼,它應該可以正常工作。

嘗試設置deferredRender爲false,一個tabpanel,或forceLayout真爲你的第二個選項卡。它將強制渲染和加載所有選項卡(deferredRender:false)或僅選項卡,在那裏您將設置forceLayout。

+0

感謝您的解決方案。它的作品:) – ashhad

0

我以同樣的方式去看Selmaril。您的視圖無法訪問。如果你願意,你可以在getView之前切換選項卡。

yourTabPanel.setActiveTab("availableagents"); 
yourTabPanel.doLayout(); 

哪裏yourTabPanel是xtype: 'tabpanel',設置一個id,你將能夠做到: Ext.getCmp( 「yourTabPanel」)setActiveTab( 「availableagents」);

+0

這也有幫助。我不知道如何使用setActivetab,直到我看到您的帖子。謝謝 – ashhad