【发布时间】:2016-03-28 09:33:49
【问题描述】:
如何撤消对数据库的未同步更改?
用例场景
我想让用户在他执行一项操作后至少几秒钟内撤消数据库操作(即删除)。
一种可能性是保留从数据库中删除的操作,直到撤消它的时间过去,但是我认为在代码中反映我将在 UI 中看到的内容会更加简化,只是为了保留内容1:1。
所以,我尝试在删除之前存储对象,然后更新它(这样它的_status 就不会再被删除了):
this.lastDeletedDoc = this.docs[this.lastDeletedDocIndex];
// remove from the db
this.documents.delete(docId)
.then(console.log.bind(console))
.catch(console.error.bind(console));
// ...
// user taps "UNDO"
this.documents.update(this.lastDeletedDoc)
.then(console.log.bind(console))
.catch(console.error.bind(console));
但我收到了错误Error: Record with id=65660f62-3eb1-47b7-8746-5d0b2ef44eeb not found。
我还尝试使用以下方法再次创建对象:
// user taps "UNDO"
this.documents.create(this.lastDeletedDoc, { useRecordId: true })
.then(console.log.bind(console))
.catch(console.error.bind(console));
但我收到 Id already present 错误。
我也快速浏览了源代码,但找不到任何undo 函数。
我通常如何撤消对未同步的 kinto 收藏的更改?
【问题讨论】:
-
这个问题是关于Kinto.js
标签: javascript undo kinto database nosql