2012-04-25 147 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 2012-04-25 17:04:23

+0

@rdougan:哎呀。我錯過了那個參考。是的,那麼就不需要調用'getCmp()'。編輯我的答案。 – 2012-04-25 17:06:31

+0

那很棒的roadRunner。謝謝你的解釋。 – 2012-04-25 20:57:28