2012-04-25 20 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()メソッドを使用してフォーム値にアクセスできなくなります。

代わりに、次のようにします。

パネルのタイプを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を働かせました。ご説明ありがとうございます。 –