2017-01-02 78 views
0

我有這樣的店:ExtJS的4.2 store.sync()創建/更新

STORE

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

這家店就是點擊一個按鈕,我可以添加一行一格,如果我選擇一些以前的(插入到數據庫中)行我可以編輯它的數據。

當所有完成後,我單擊一個按鈕將商店與數據庫同步。

此按鈕調用函數與此代碼:

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

我可以同步在兩個步驟店裏,第一個新記錄,然後修改的記錄,因爲我需要知道,如果這兩個動作,其中成功?因爲用戶可以添加新行並編輯一些舊行。

回答

0

商店的「beforesync」事件可能在此處有用。第一個參數是操作類型爲鍵的對象,操作列表爲值。所以你可能會操縱什麼樣的操作將被執行。

+0

謝謝,我會試試看。 – SensacionRC