2013-04-28 2 views
0

'IMS.SellMgt.testForm'클래스를 정의했습니다. '제출'버튼을 클릭하면 'var test = this.formPanel;'을 가져오고 싶습니다. 왜 테스트가 null입니까? 내가 이걸 얻고 싶다면 폼 패널. 어떻게 할 수 있니? 고마워! 같은Extjs에서 클래스 인스턴스를 얻으려면 어떻게해야합니까?

Ext.define('IMS.SellMgt.testForm', { 
    formPanel: null, 
    LoadForm: function() { 
      this.formPanel = new Ext.form.Panel({ 
      renderTo: 'form-ct', 
      frame: true, 
      title: 'XML Form', 
      width: 300, 
      items: [{ 
       xtype: 'fieldset', 
       title: 'Contact Information', 
       defaultType: 'textfield', 
       items: [{ 
        fieldLabel: 'First Name', 
        emptyText: 'First Name', 
        name: 'first' 
       } 
      ] 
      }], 
      buttons: [{ 
       text: 'Submit', 
       handler: function() { 
        var test = this.formPanel; 
         } 
      }] 
     }); 
    } 
}); 

Ext.onReady(function() { 
    var frmTest = Ext.create('IMS.SellMgt.testForm', {}); 
    frmTest.LoadForm(); 
}); 

답변

0

시도 뭔가 :

...... 
handler: function() { 
    var test = this.findParentByType(Ext.form.FormPanel); 
} 
.... 
0

handler 버튼의 클릭 이벤트 리스너를 지정하는 간단한 방법입니다. 짧은 손이므로 몇 가지 단점이 있습니다. handler 함께

는 함수의 문맥 항상 버튼이다. 즉, 핸들러 함수 안에있는 this은 양식이 아니라 단추입니다.

handler: function() { 
    var form = this.up('form'); 
    ... 
} 
:

buttons: [{ 
    text: 'Submit', 
    listeners: { 
     click: function() { 
      this.formPanel; // will work now 
      ... 
     }, 
     scope: this // this is the key 
    } 
}] 

또한 양식을 찾기 위해 up를 사용할 수 있습니다 this에 대한

위해

는 지정된 범위에 리스너를 사용하여 클래스가 될 수 있습니다

관련 문제