存储在启用自动同步的同步后做一些事情 [英] Store do something after sync with autoSync enabled
问题描述
我正在尝试检测并删除同步后仍在存储中但未添加到数据库中的那些字段(成功:false).然后,向用户返回错误消息(带有一些错误代码).但是,我只能在商店文档中看到beforesync"事件.
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?
请注意,我正在使用 autoSync,这就是为什么我不能挂钩回调的原因,否则一切都会变得更容易.
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:
代码:
Ext.data.Model.EDIT
Ext.data.Model.REJECT
Ext.data.Model.COMMIT
为什么 REJECT 事件永远不会被触发?我想如果成功 = false REJECT 会被调用,我是否需要像 404 这样的东西才能获得那个结果?
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?
不,我找不到触发更新事件的拒绝版本的方法.有什么建议吗?
No, I can't find a way to fire REJECT version of the update event. Any suggestion?
推荐答案
如果你问我,这是 ExtJS 中的一些设计缺陷.
This is, if you ask me, some design flaw in ExtJS.
AbstractStore 有 onCreateRecords
、onUpdateRecords
和 onDestroyRecords
,它们是可以覆盖的空函数.如果成功失败,您可以调用 rejectChanges().
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);
},
});
这篇关于存储在启用自动同步的同步后做一些事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!