本文介绍了存储在启用autoSync同步后执行某些操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检测并删除同步后仍然存储但未添加到数据库中的那些字段(success:false)。然后,向用户返回错误消息(含有一些错误代码)。但是,我只能在商店文档中看到beforesync事件。



有没有可能做这样的事情?我正在尝试使用更新事件,但只有在同步成功时才会同步才可以进行调用(否则,只能在同步之前调用)。



我不能真的会发现同步后触发的事件。
任何解决方案?



请注意,我正在使用autoSync,这就是为什么我无法挂接到回调,否则一切都会更容易。 / p>

我可以在文档中看到另一个重要的一点:



代码:

  Ext.data.Model.EDIT 
Ext.data.Model.REJECT
Ext.data.Model.COMMIT

为什么REJECT事件永远不会被触发?我认为如果成功= false REJECT将被调用,我需要像404这样的结果吗?



编辑:不,我找不到一种方式触发REJECT版本的更新事件。任何建议?

解决方案

这是,如果你问我ExtJS中的一些设计缺陷。



AbstractStore具有 onCreateRecords onUpdateRecords onDestroyRecords ,它们是可以覆盖的空函数。如果成功为false,可以调用rejectChanges()。

  Ext.define('BS。 store.Users',{
extends:'Ext.data.Store',
model:'BS.model.User',

autoSync:true,
autoLoad:true,

proxy:{
type:'direct',
api:{
create:Users.Create,
read:Users。获取,
更新:Users.Update,
destroy:Users.Delete,

},
reader:{
type:'json',
root:'data',
},
},

onCreateRecords:function(records,operation,success){
console.log(records) ;
},

onUpdateRecords:function(records,operation,success){
console.log(records);
},

onDestroyRecords:function(records,operation,success){
console.log(re线);
},

});


I'm trying to detect and remove those fields that after a sync are still on the store but are not added to the database (success: false). Then, return an error message to the user (with some error codes). However I can only see a "beforesync" event in store documentation.

Are there any possibility to do such a thing? I'm trying with "update" events but they are called after syncing only if the sync is successfull (otherwise they are called only before sync).

I can't really find an event that is fired after sync.Any solution for this?

Notice that I'm using autoSync, that's why I can't hook to the callback, otherwise everything will be easier.

Another important point I can see in the documentation is:

Code:

Ext.data.Model.EDIT
Ext.data.Model.REJECT
Ext.data.Model.COMMIT

Why REJECT event is never fired? I thought that if success = false REJECT would be called, do I require something like a 404 to obtain that result?

EDIT: No, I can't find a way to fire REJECT version of the update event. Any suggestion?

解决方案

This is, if you ask me, some design flaw in ExtJS.

AbstractStore has onCreateRecords, onUpdateRecords, and onDestroyRecords, which are empty functions you can override. You can call rejectChanges() if success is false there.

Ext.define('BS.store.Users', {
    extend: 'Ext.data.Store',
    model: 'BS.model.User',

    autoSync: true,
    autoLoad: true,

    proxy: {
        type: 'direct',
        api: {
            create: Users.Create,
            read: Users.Get,
            update: Users.Update,
            destroy: Users.Delete,

        },
        reader: {
            type: 'json',
            root: 'data',
        },
    },

    onCreateRecords: function(records, operation, success) {
        console.log(records);
    },

    onUpdateRecords: function(records, operation, success) {
        console.log(records);
    },

    onDestroyRecords: function(records, operation, success) {
        console.log(records);
    },

});

这篇关于存储在启用autoSync同步后执行某些操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 12:14
查看更多