0

次の例では、ボタンをクリックすると、すべてのフォーム データ (両方ともKEY-VALUE) が php ファイルに渡され、データベースに保存されます。のグラブは、ステートメントKEY-VALUEによって行われます。var form = this.up('form').getForm();

更新 3

Ext.define ('Mycomp.model.MyClass',{
    extend: 'Ext.data.Model',

    fields:['textfieldone']

});

================================================== ======================

更新 2

ユーザーがボタンをクリックすると、1 つのテキスト フィールドとボタンを持つビューが表示されます (次のコードを参照)。ユーザーがいくつかの値を入力してボタンをクリックすると、ユーザーがテキスト フィールドに入力した値が DB に保存されます ( StorePHP コードのパスへのリンクがあります)。

コントローラ

Ext.define('Mycomp.controller.MyClass',{
    extend: 'Ext.app.Controller',

    stores:['MyClass'],
    models:['MyClass'],
    views:['MyClassView'],
    init: function(){
        this.control({          
            'myclassview button[action=save]': {
                click: this.myMethod
            }
        });         
        },
        myMethod: function(button,record) {
               var win    = button.up('window'),
               form   = win.down('form'),
               record = form.getForm().getRecord(),
               values = form.getForm().getValues();
               console.log (values);
               console.log (record);
               record.getRecord().set(values);         
           win.close();
           this.this.getMyClassStore().sync(); 
    }
});

見る

Ext.define('Mycomp.view.user.MyClassView', {
    extend: 'Ext.window.Window',
    alias: 'widget.myclassview',
    initComponent: function() {
        this.items = [
            {
                xtype: 'form',
                items: [
                    {
                        xtype: 'textfield',
                        name : 'textfieldone',
                        fieldLabel: 'Contact Person Name'
                    }
                ]
            }
        ];
        this.buttons = [
                        {
                            text: 'Save',
                            name:'save',
                            action: 'save'
                        }
                    ];
        this.callParent(arguments);
    }
});

お店

Ext.define('Mycomp.store.Myclass',{
    extend:'Ext.data.Store',
    model:'App.model.Myclass',

    proxy: {
        actionMethods : {
            create : 'POST'
        },
        type: 'ajax',
        url : '/savetodb.php'

    }

});

================================================== =============================

更新 1

 ....  this.buttons = [
                            {
                                text: 'Save',

                                action: 'save'
                            }, ...

お店

Ext.define('Mycomp.store.Myclass',{
    extend:'Ext.data.Store',
    model:'App.model.Myclass',

    proxy: {
        actionMethods : {
            create : 'POST'
        },
        type: 'ajax',
        url : '/savetodb.php'

    }

});

コントローラー

this.control({

            'mycalssform button[action=save]': {
                click: this.myMethod
            }
        });


        },

        myMethod: function(button, record) {

               var win    = button.up('window'),
               form   = win.down('form'),
               record = form.getRecord(),
               values = form.getValues();
               console.log (record);
      console.log (values );

           record.set(values);
           win.close();
           this.this.getmyClassStore().sync(); 

FIREBUG OUT PUT >> RECORD IS UNDEFINED と表示されます。どうしてこれなの ?

undefined

Object { textfileldone="hello", textfileldtwo="bever", more...}

record is undefined
[Break On This Error]   

record.set(values);
4

1 に答える 1

2

フォームがレコードに「バインド」されるためには、新しいモデル インスタンスを作成して呼び出す必要があります。form.loadRecord()これを行った後にのみ、機能しform.getRecord()ます。

別の方法として (新しいレコードのみを使用する場合に適しています)、保存時に新しいモデル レコードを作成し、その値を設定することもできます。

これらの行に沿った何かは、新しいモデル レコードを作成します。

var iStore = this.getmyClassStore();
var iModel = iStore.model; 
var iNewRecord = iModel.create();

その後、次を実行できます。

iValues = form.getValues();
iNewRecord.set( iValues );

次に、ストアに新しいレコードを追加する必要があります。

iStore.add( iNewRecord )

したがって、コードは次のようになります。

    myMethod: function(button, record) {

           var win    = button.up('window'),
               form   = win.down('form'), 
               values = form.getValues(),
               store = this.this.getmyClassStore(),
               model = store.model,
               record = model.create();


               record.set( values );
               store.add( record );
               win.close();
               store.sync(); 
    }
于 2012-07-03T12:24:05.090 に答える