1

MVCSenchaTouchプロジェクトを作成しました。ユーザーがユーザー名とパスワードを入力してWebサービスに送信するサンプルアプリケーションを作成しました。

ユーザー名とパスワードのフィールドは「VIEW」にあると想定されており、「Webサービスへの送信」機能は「CONTROLLER」にある必要があります。

私のプログラムでは、Webサービスへの送信部分も「VIEW」にあるので、誰かが私のコードを編集するのを手伝ってくれませんか。そうすれば、「CONTROLLER」で「Webサービスに送信」機能を使用できます。

これがコードです

Ext.define('TU.view.Contact',{
           extend:'Ext.form.Panel',
           xtype:'contactform',

           config: {

           title:'Contact',
           iconCls:'user',

           url:'http://somesite.com/contact.php',
           items: [
           {
                   xtype:'fieldset',
                   title:'User Login',

                   items:[
                          {
                          xtype:'textfield',
                          name:'name',
                          label:'Name'
                          },
                          {
                          xtype:'passwordfield',
                          name:'password',
                          label:'Password'
                          }
                          ]
           },
           {
                   xtype:'button',
                   text:'Send',
                   ui:'confirm',
                   padding:5,
                   handler:function(){
                   this.up(contactform).submit();

                   }
           }
           ]



           }




           });
4

1 に答える 1

1

まず、idボタンのプロパティを設定します。

 xtype:'button',
 id:'submitBtn',
 text:'Send'
 .....
 .....

コントローラクラスでは、

Ext.define('MyApp.controller.Main', {
    extend: 'Ext.app.Controller',

    config: {
        refs : {
            submitBtn: '#submitBtn'
        },

        control : {
            submitBtn: {
                tap: 'submitData'
            }
        },
    },

    submitData: function() {
             var form = Ext.getCmp('form-id');

             // Get username and password fields ...
             var formvalues = form.getValues();

             // Web Service code goes here ..
             Ext.Ajax.request({
                 params: formvalues,                     
                 url:'http://_servername_.com/app/insert.php'

                 success : function() {
                       Ext.Msg.alert('Success','Username and password successfully entered');
                 }

                 failure : function() {
                       Ext.Msg.alert('Failure','Error while adding data');
                 }
             });        
    }
});

注: insert.phpデータベースと接続して値を入力するサーバー側のコード(例)になります。

于 2012-05-05T16:54:06.737 に答える