存储同步:许多删除,有些失败 [英] Store sync: Many deletions, some failed
问题描述
我有一个商店,用户可以使用单个 destroy
操作删除多个记录。
I have a store in which the user could delete multiple records with a single destroy
operation.
现在,这些记录中的一些被锁定在数据库中(因为其他人正在处理它们),因此无法被删除。服务器如何告诉前端删除id a,b,c的记录是成功的,但是id x,y,z的记录不能被删除,应该被移回商店并显示在网格中?
Now, a few of these records are locked in the database (because someone else is working on them), and thus cannot be deleted. How can the server tell the frontend that the deletion of records with Id a, b, c was successful, but that records with Id x, y, z could not be deleted and should be moved back into the store and displayed in the grid?
ExtJS商店应该在 sync()
之后知道哪些记录在服务器端被真正删除,哪些是't。
The ExtJS store should know after the sync()
which records were really deleted server-side, and which weren't.
推荐答案
我认为这个问题没有直接的解决方案。我已经选择了以下解决方法:
I think there's no straightforward solution to this problem. I have opted for the following workaround:
记录现在有一个IsDeleted标志设置为 false
默认情况下:
The records now have an "IsDeleted" flag that is set to false
by default:
fields:[{
...
},{
name: 'IsDeleted'
type: 'bool',
defaultValue: false
商店有一个过滤器,将标记设置为的条目隐藏
:
The store has a filter that hides entries where the flag is set to true
:
filters:[{
property:'IsDeleted',
value:false
}]
当用户选择删除时,我不从商店中删除条目,而是设置 IsDeleted
标记为 true
。过滤器使用户认为该条目已被删除。
When the user opts to delete, I don't remove
entries from the store, instead I set the IsDeleted
flag to true
on these entries. The filter makes the user think that the entry has been deleted.
当商店同步时,它执行更新
操作,而不是破坏
操作。因此,API的更新端点必须删除 IsDeleted
作为 true
发送的所有条目。如果它不能从数据库中删除条目,则返回给客户端的相应json将获得 IsDeleted
设置为 false
,以便前端知道该条目的删除失败。
When the store syncs, it does an update
operation, not a destroy
operation. So the update endpoint of the API then has to delete all entries where IsDeleted
is transmitted as true
. If it can't delete an entry from the database, the corresponding json as returned to the client gets IsDeleted
set to false
, so that the frontend gets to know that the deletion of that entry failed.
这篇关于存储同步:许多删除,有些失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!