Sencha Touch 2表格

时间:2012-04-25 12:08:46

标签: sencha-touch 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 个答案:

答案 0 :(得分: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

相关问题