2016-07-29 69 views
0

我必須插入對象作爲面板項目。我創建了對象,並在Panel中將項目放置爲一個數組。然後如何將該對象添加到數組的項目中。如何插入對象作爲面板項目

我的代碼:

{ 
    title : "Records", 
    bodyStyle: 'background: #dfe8f6;border:#dfe8f6;', 
    autoScroll: true, 
    id:'ExcludeRecord', 
    region: 'center', 
    layout:{ 
     type: 'vbox', 
     pack: 'start', 
     align: 'stretch' 
    }, 
    items: [], 
    }` 

回答

0

你可以把對象在項目數組

{ 
    title : "Records", 
    bodyStyle: 'background: #dfe8f6;border:#dfe8f6;', 
    autoScroll: true, 
    id:'ExcludeRecord', 
    region: 'center', 
    layout:{ 
     type: 'vbox', 
     pack: 'start', 
     align: 'stretch' 
    }, 
    items: [{ 
      xtype:'panel', 
      html:'Your Object' 
      }], 
    } 
2

您可以使用下面的代碼將項目添加到面板:

var panel = Ext.getCmp('ExcludeRecord'); 
panel.add(object); // Your object. 
panel.doLayout(); 

我希望它能爲你工作。

+0

我可以在任何'beforerender'或'afterrender'函數或'initComponent'函數中寫入。 – David

+0

是的,你可以在任何函數中編寫函數,但是你必須在這個函數中有這些對象。 Ext.apply(me,{ items:[{object}], }); me.callParent(arguments); 您可以在initComponent中使用上述代碼將該對象直接作爲項目。 –

+0

對於多記錄,我正在使用'for'循環。然後'panel.doLayout()'應該在裏面for循環的權利。在那種情況下,只有一個時間對象出現。 – David