2010-06-18 21 views
2

如果我有:ExtJS的重用對象

var x = new Ext.form.formPanel({ 
}); 

我想在兩個地方重複使用,例如:

var panel1 = new Ext.panel({ items:[x] }); 
var panel2 = new Ext.panel({ items:[x] }); 

有嘗試方法Ext.extend,但沒有奏效。如果我這樣做,它只會在頁面上呈現一次。

回答

1

兩個Ext.form.FormPanel對象需要被創建,所以你必須做類似的東西什麼如下圖所示:

var x = new Ext.form.FormPanel({ 
}); 

var y = new Ext.form.FormPanel({ 
}); 

var panel1 = new Ext.Panel({ items:[x] }); 
var panel2 = new Ext.Panel({ items:[y] }); 
1

,你可以創建自己的FormPanel中的類,然後創建這個每次你想

MyForm = Ext.extend(Ext.form.FormPanel, { 
    title: 'My Personal Form', 
    width: 400, 
    height: 250, 
    padding: 10, 
    initComponent: function() { 
    this.items = [ 
     { 
      xtype: 'textarea', 
      anchor: '100%', 
      fieldLabel: 'Label' 
     }, 
     { 
      xtype: 'textfield', 
      fieldLabel: 'Label', 
      anchor: '100%' 
     } 
    ]; 
    MyForm.superclass.initComponent.call(this); 
    } 
}); 

var panel1 = new Ext.panel(new MyForm({id:'test1'})); 
var panel2 = new Ext.panel(new MyForm()); 

我在第一個面板插入一個id屬性,但您可以插入任何其他東西。 您也可以更改表格的標準配置,覆蓋配置