2012-07-24 34 views
0

創建的getter/setter我有我創建了一個組件代碼。在點擊申請時,我想保存這個表單域對象並使其可用於獲取。所以父容器可以讀取它。ExtJS的如何組件

我也希望所有領域的getter/setter,這樣可以更新值運行。如何實現這一目標?

Ext.define('MyApp.view.MyForm', { 
    extend: 'Ext.form.Panel', 

    height: 463, 
    width: 227, 
    bodyPadding: 10, 
    title: 'My Form', 

    initComponent: function() { 
     var me = this; 

     Ext.applyIf(me, { 
      items: [ 
       { 
        xtype: 'textfield', 
        fieldLabel: 'Component Name', 
        anchor: '100%' 
       }, 
       { 
        xtype: 'textfield', 
        fieldLabel: 'Host', 
        anchor: '100%' 
       }, 
       { 
        xtype: 'textfield', 
        fieldLabel: 'Port', 
        anchor: '100%' 
       }, 
       { 
        xtype: 'textfield', 
        fieldLabel: 'Path', 
        anchor: '100%' 
       }, 
       { 
        xtype: 'textareafield', 
        fieldLabel: 'Request Data', 
        anchor: '100%' 
       }, 
       { 
        xtype: 'button', 
        text: 'Apply', 
        listeners: { 
         click: { 
          fn: me.onButtonClick, 
          scope: me 
         } 
        } 
       } 
      ] 
     }); 

     me.callParent(arguments); 
    }, 
     onButtonClick: function(button, e, options) { 
        var form = this.getForm(), 
      values = form.getFieldValues(), 
        //make this available to public 
      json = Ext.JSON.encode(values); 
      console.log(json); 


    } 

}); 
+0

任何幫助表示讚賞。 – 2012-07-24 13:28:25

回答

0

爲了實現這個需要定義config中的所有變量:{} extjs會自動創建getter/setter。

然後,您可以使用this.getVar(),this.setVar()

我希望這是對初學者很有幫助引用它。