Store sync: Many deletions, some failed

两盒软妹~` 提交于 2019-12-23 18:21:02

问题


I have a store in which the user could delete multiple records with a single destroy operation.

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?

The ExtJS store should know after the sync() which records were really deleted server-side, and which weren't.


回答1:


I think there's no straightforward solution to this problem. I have opted for the following workaround:

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
}]

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.

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.



来源:https://stackoverflow.com/questions/43652956/store-sync-many-deletions-some-failed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!