2012-04-25 15 views
2

나는 양식 텍스트 필드가있는 팝업 창이 있습니다. 텍스트 필드에 어떻게 액세스 할 수 있습니까? 내 시도는 다음과 같습니다.Sencha Touch 2 양식

function foo(){ 
    bar = Ext.Viewport.add({ 
    xtype: 'panel', 
    scrollable: true, 
    centered: true, 
    width: 400, 
    height: 300, 
    items:[{ 
      xtype: 'textfield', 
      name: 'name', 
      label: 'Name' 
     }, { 
      docked: 'bottom', 
      xtype: 'titlebar', 
      items:[{ 
        xtype: 'button', 
        ui: 'normal', 
        text: 'Send', 
        go: 'testsecond', 
        handler:function(){ 
         alert(bar.getValues().name); 
        } 
      }] 
     }] 
    }); 
} 

답변

1

아니요. 당신은 이렇게 할 필요가 없습니다. xtype:'panel'을 설정하면 form.getValues() 메소드를 사용하여 양식 값에 액세스하지 못하게됩니다.

대신 다음과 같이하십시오.

패널 xtype을 formpanel으로 지정하십시오.

이 아래를 참조

bar = Ext.Viewport.add({ 
    xtype: 'formpanel', 
    scrollable: true, 
    centered: true, 
    width: 400, 
    height: 300, 
    items:[{ 
      xtype: 'textfield', 
      name: 'name', 
      label: 'Name' 
     }, { 
      docked: 'bottom', 
      xtype: 'titlebar', 
      items:[{ 
        xtype: 'button', 
        ui: 'normal', 
        text: 'Send', 
        go: 'testsecond', 
        handler:function(){ 
         Ext.Msg.alert("Name: "+bar.getValues().name); 
        } 
      }] 
     }] 
    }); 

귀하의 출력이되어야합니다 :

enter image description here

+0

당신은'여기 전화 getCmp' 필요가 없습니다. 당신은 이미'bar' 변수를 사용하여 폼에 대한 레퍼런스를 가지고 있습니다. – rdougan

+0

@rdougan : 죄송합니다. 나는 그 참조를 놓쳤다. 예, 그렇다면'getCmp()'를 호출 할 필요가 없습니다. 내 대답 편집. –

+0

위대한 roadRunner에서 효과가있었습니다. 설명해 주셔서 감사합니다. –