-1

重複の可能性:
フォームの値を取得し、sencha touch を使用してその値をデータベースに挿入する方法

sencha touch は初めてです。フォームを作成し、そのフォームの詳細をデータベースに送信したいと考えています。このために、次のコードを記述します。

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);
                            }

                        });

                    }

                }
    }
]
}
});

このアプリを実行しようとすると、正常に実行 (デバッグ) されます。ブラウザでアプリケーションを開くと、コンソール ウィンドウに "Uncaught TypeError: Cannot call method 'getValues' of undefined" というエラーが表示され、フォームのみが表示されます。送信ボタンをクリックしても何も起こりません。これを解決するのに役立つ人はいますか? 前もって感謝します...

4

2 に答える 2

0

それ以外の

var values = thisTxt.getValues();

試す

var values = form.getValues();

また

var values = this.parent.getValues();

ボタンthisTxtはフォームではなく、フォームパネルでgetValues()を呼び出す必要があるためです。

于 2013-01-17T10:50:53.420 に答える
0

まず、idフォームを間違った場所に配置します。構成の外に配置する必要がありitemsます

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

次に、クエリが間違っています。次のクエリを変更してください。

var form = Ext.getCmp(form);

これに:

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

最後にgetvalues、フォーム内の各フィールドの値を含むオブジェクトを返すので、たとえばnameフィールドにアクセスする場合は、次のようにします。

alert(values.name);

それが役に立てば幸い :)

于 2013-01-17T07:43:42.330 に答える