【问题标题】:Extjs 4.2 store.sync() creating/updatingExtjs 4.2 store.sync() 创建/更新
【发布时间】:2017-01-02 10:59:20
【问题描述】:

我有这家店:

商店

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

我可以分两步同步存储,首先是新记录,然后是修改记录?因为我需要知道这两个操作是否成功。因为用户可以添加新行并编辑一些旧行。

【问题讨论】:

    标签: extjs extjs4.2


    【解决方案1】:

    商店的“beforesync”事件可能在这里有用。第一个参数是一个对象,操作类型为键,操作列表为值。因此,您也许可以操纵将执行的操作类型。

    【讨论】:

    • 谢谢,我试试看。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-30
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-27
    相关资源
    最近更新 更多