2011-09-29 52 views
0

我新接觸sencha,並且我創建了一個接受用戶名和密碼以及登錄按鈕的登錄表單,所以當我點擊登錄按鈕時我應該得到用戶ID值爲alert.and代碼爲如何獲取表單值當我點擊提交in sencha touch

Ext.setup ({ 
onReady: function() { 

    var myform=new Ext.form.FormPanel({ 
    id:'form', 
    fullscreen:true, 
    standardSubmit:true, 
    dockedItems:[{ 
    Dock:'top', 
    xtype:'toolbar', 
    height:40, 
    title:'Tool Bar', 
    id:'login', 
    } 
    ], 
    items:[{ 
xtype:'textfield', 
name:'id', 

width:'50%', 
align:'center', 
label:'User Id' 
}, 
{ 
xtype:'textfield', 
name:'pwd', 
id:'pwd', 
width:'50%', 
align:'center', 
label:'Password' 
}, 

{ 
    xtype:'button', 
    ui:'round', 
    width:'50%', 
    text:'Login', 
    align:'center', 
    handler:function() 
    { 
    gettingvalues();/* var fields = form.getValues(); 
    console.log(fields['name']); */ 

    } 
} 
], 

    }); 

    gettingvalues=function() 
    { 
     var fields=myform.getValues(); 
     Ext.Msg.alert(fields['id'].getValue()); 
    } 


} 

});

但我沒有得到任何警報價值,我必須做的。 之後,我希望將這些值發送到我們的本地服務器,需要ID和密碼,這將是格式... oururl?行動=登錄& ID = XYZ & PWD =在該XYZ, 它會接受並返回迴應,所以爲了這個我必須寫, 請讓我儘快知道。 在此先感謝。

回答

0

你嘗試過:

var fields=myform.getValues(); 
Ext.Msg.alert(fields['id']); 

你得到任何JavaScript錯誤?

1

您可以通過他們的name屬性獲取表單值,如:

{ 
    xtype:'button', 
    ui:'round', 
    width:'50%', 
    text:'Login', 
    align:'center', 
    handler:function() 
    { 
    var form = myForm.getValues(); 
    console.log('Form Object: ' + form); 
    console.log('User ID Field: ' + form.id); 
    console.log('Password Field: ' + form.pwd);   
    } 
}