getting error when calling the function using sencha touch [duplicate]

橙三吉。 提交于 2019-12-13 08:01:07

问题


Possible Duplicate:
how to get the form values and insert that values in the db using sencha touch

im new to sencha touch.I want to create a form and submit that form details in the database .for this one i write the following code.

Ext.define("Form.view.Main",{
extend: "Ext.form.Panel",

 requires:['Ext.Button',
            'Ext.Spacer',
            'Ext.field.Password'
 ],
config: {
  fullscreen: true,
   id:'form',
items: [
    {
        xtype:'fieldset',
       items:[

           {
               xtype: 'textfield',
               name : 'name',
               label: 'Name'
           },
           {
               xtype: 'emailfield',
               name : 'email',
               label: 'Email',
               placeHolder: 'Email address',
               useClearIcon: true
           },
           {
               xtype: 'passwordfield',
               name : 'password',
               label: 'Password',
               allowBlank:'false'
           }
       ]

},
     {
                centered:'true',
                xtype:'button',
                id:'submitBtn',
                text:'Submit',
                ui:'confirm',
                width:100,
               listeners: {
                    tap : function(thisTxt,eventObj){
                        var form = Ext.getCmp('form');
                        var values = thisTxt.getValues();
                        alert(values.name);
                        Ext.Ajax.request({
                            url:'http://localhost/sencha2011/form/insert.php',
                            params:values,

                            success : function(response){
                                var text = response.responseText;
                                Ext.Msg.alert('Success', text);
                            },
                            failure : function(response){
                                Ext.Msg.alert('Error','Error while submitting the form');
                                console.log(response.responseText);
                            }

                        });

                    }

                }
    }
]
}
});

when i try to execute this app ,executed(debug) successfully.when i open the application in the browser ,i have the error as " Uncaught TypeError: Cannot call method 'getValues' of undefined " in console window,and form only displayed .when i click the submit button nothing happens.can any one help to solve this one. thanks in advance...


回答1:


Firstly, you put id of your form at the wrong place, it should be placed outside of the items config

config: {
  fullscreen: true,
  id: 'form'
  items: [
  ...........
}

Secondly, your query is wrong, change this query:

var form = Ext.getCmp(form);

to this:

var form = Ext.getCmp('form');

Finally, since getvalues will return you an object containing the value of each field in the form so if you want to access, for instance, your name field, just do like this:

alert(values.name);

Hope it helps :)




回答2:


Instead of

var values = thisTxt.getValues();

try

var values = form.getValues();

or

var values = this.parent.getValues();

because thisTxt is the button not the form, and getValues() should be called on form panel.



来源:https://stackoverflow.com/questions/14372967/getting-error-when-calling-the-function-using-sencha-touch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!