2017-01-02 6 views
0

を更新/作成:ExtJSの4.2 store.sync()私はこのストアを有する

Ext.define('App.mystore', { 
extend: 'Ext.data.Store', 
model:  'App.mymodel', 
autoLoad: false, 
proxy: { 
    type: 'ajax', 
    api: { 
     read: 'read.php', 
     create: 'create.php', 
     update: 'update.php' 
    }, 
    reader: { 
     type: 'json', 
     root: 'data', 
     totalProperty: 'total', 
     successProperty: 'success' 
    }, 
    writer: { 
     root: 'records', 
     encode: true, 
     writeAllFields: false 
    } 
} 
}); 

STOREこの店は、私は、行を追加することができ、ボタンをクリックするグリッドであり、場合に以前の(データベースに挿入されている)行を選択して、そのデータを編集することができます。

すべて完了したら、ボタンをクリックしてストアをデータベースと同期させます。

このボタンは、このコードで関数を呼び出す:?私は両方のアクションであればどこに成功を知っておく必要があるため

onSave:function(){ 
    var Store=Ext.ComponentQuery.query('mygrid')[0].getStore(); 

    Store.getProxy().setExtraParam('param1',this.Param1); 
    Store.getProxy().setExtraParam('param2',this.Param2); 
    Store.getProxy().setExtraParam('param3',this.Param3); 

    Store.sync({ 
     scope:this, 
     success : function(response){ 
      Ext.Msg.show({ 
       title: 'Information', 
       msg: 'All OK', 
       icon: Ext.MessageBox.INFO, 
       buttons: Ext.Msg.OK 
      }); 
     }, 
     failure:function(response){ 
      Ext.Msg.show({ 
       title: 'warning', 
       msg: 'Error', 
       icon: Ext.MessageBox.WARNING, 
       buttons: Ext.Msg.OK 
      }); 
     } 
    }); 
}, 

は、私は2つのステップで店舗、最初の新しいレコード、その後、変更されたレコードを同期することができます。ユーザーは新しい行を追加したり、古い行を編集したりできるためです。

答えて

0

店舗の「beforesync」イベントが便利な場合があります。最初の引数は、操作型をキーとするオブジェクトと、値としての操作のリストです。したがって、どのような操作を実行するかを操作することができます。

+0

ありがとう、私はそれを試してみます。 – SensacionRC

関連する問題