2013-03-18 105 views
0

我是sencha touch框架中的新成员。我试图首先创建用户登录。我想从表单中获取用户名和密码并发送到api进行身份验证。但我甚至无法获得字段值。我的LoginForm视图如下所示:检索sencha touch 2 fieldsetss值

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

看起来你已经忘记了()在结束this.getLoginForm在你的回调中。尝试切换到

success: function(user){ 
    var values=this.getLoginForm().getValues(); 
           //^^------these ones 
    console.log(values.username); // want to see this output 
} 
+0

感谢您的回复,但即使在this.getLoginForm的末尾添加()后也有同样的错误。我有两个不同的配置文件:平板电脑和手机。我想知道这是否是问题? – Shree 2013-03-18 13:03:22

+0

嗯,你可以尝试改变你的参考'loginForm:'loginForm''。你有什么应该工作,但只是为了确保。 – jprofitt 2013-03-18 14:01:38

+0

解决了这个问题。谢谢 – Shree 2013-03-18 14:59:04