有没有办法“观察”IndexedDB记录,以便在更改时作出响应?(Is there a way to “watch” an IndexedDB record so I can respond when

编程入门 行业动态 更新时间:2024-10-28 06:33:14
没有办法“观察”IndexedDB记录,以便在更改时作出响应?(Is there a way to “watch” an IndexedDB record so I can respond when it's been changed?)

我正在构建一个使用IndexedDB在本地存储数据的Angular + TypeScript应用程序。


我有一个Angular指令,它将scope变量的值设置为从IndexedDB请求返回的一些数据。 这非常简单,并执行如下操作:

指令A:

// getGroup() is making the requests to IndexedDB: this.dataService.getGroup().then((groupOne) => { this.scope.items = groupOne.items; });

指令B:

groupOne.items.push("a new item"); this.dataService.updateGroup(groupOne).then(() => { // groupOne has been changed! // how can I let Directive A know about this, so Directive A can update its scope.items? });

Directive A:

// getGroup() is making the requests to IndexedDB: this.dataService.getGroup().then((groupOne) => { this.scope.items = groupOne.items; });

Directive B:

groupOne.items.push("a new item"); this.dataService.updateGroup(groupOne).then(() => { // groupOne has been changed! // how can I let Directive A know about this, so Directive A can update its scope.items? });

Of course, Directive A does not know about the changes Directive B made to groupOne unless it does another request. And therefore, my view is "static".

I know I could wrap Directive A's IndexedDB request into an interval and be checking for updates, but that seems like a strange way to solve this problem.

Is there a way with IndexedDB to be notified of this change? Is there something Angular provides that could help with this (something similar to $scope.$watch()) ?

最满意答案

还没有一种方法可以用纯粹的IndexedDB来做到这一点,但它正在被原型化。 这个名字是“观察者”。 如果你喜欢,你可以尝试使用polyfill 。

There is not yet a way to do this with pure IndexedDB but it is being prototyped. The name is "Observers". You can try to use the polyfill if you are so inclined.

更多推荐

本文发布于:2023-08-01 00:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1351777.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有办法   IndexedDB   watch   changed   respond

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!