我是sencha触控框架的新手。我首先尝试创建用户登录。我想从表单中获取用户名和密码,然后发送到api进行身份验证。但我甚至无法获得字段值。我的LoginForm视图如下所示:
Ext.define('NCAPP.view.tablet.LoginForm', {
extend: 'Ext.form.Panel',
xtype:'loginForm',
id:'loginForm',
config: {
items: [
{
xtype: 'image',
src:'resources/img/netcenter_logo.png',
height: 100
},
{
xtype: 'fieldset',
title: 'NCAPP LOGIN:',
items: [
{
xtype: 'textfield',
id:'fldUsername',
name:'username',
placeHolder: 'Username'
},
{
xtype: 'textfield',
id:'fldPassword',
name:'passowrd',
placeHolder: 'Password'
}
]
},
{
xtype: 'button',
id: 'btnLogin',
text: 'Login'
}
]
}
});
和我的登录控制器:
Ext.define('NCAPP.controller.tablet.LoginController', {
extend: 'Ext.app.Controller',
config: {
refs: {
loginForm:'#loginForm'
},
control: {
'#btnLogin':{
tap:'onLoginButtonTap'
}
}
},
onLoginButtonTap:function(){
var values=this.getLoginForm().getValues();
console.log(values.username); // want to see this output
Ext.ModelMgr.getModel('NCAPP.model.User').load(1,{
success: function(user){
//to do
},
failure: function(user){
console.log("failed");
}
});
},
init:function(application){
}
});
我无法获取用户名字段的值。显示的错误是:
Uncaught TypeError: Object function () {
return this.constructor.apply(this, arguments);
} has no method 'LoginForm'
或有时这个错误:
Uncaught TypeError: Cannot call method 'getValues' of undefined
请有人帮帮我....谢谢
答案 0 :(得分:0)
您的回调中似乎忘记了()
末尾的this.getLoginForm
。尝试将其切换到
success: function(user){
var values=this.getLoginForm().getValues();
//^^------these ones
console.log(values.username); // want to see this output
}