问题标签 [indexeddb]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
php - 使用jquery缓存indexeddb中的图片供离线使用
我有一个图片较多的网页,需要在移动设备上离线查看。
我发现一个jquery 插件/教程确实将图像存储在本地存储中,但这不适用于我的目的。
这是可以很容易地适应使用 indexeddb 的东西吗?
此外,我的图像将定期更新。有没有办法可以在一段时间后自动清除缓存的版本,并强制用户从网络重新加载?
javascript - IndexedDB:查询值“包含”的索引
我认为答案是“你不能那样做”,但我想确定一下。假设我有一个对象:
我想在 phoneNumbers 上创建一个索引:
稍后我想查询具有特定电话号码的人:
那会产生结果吗?如果没有,还有其他方法可以做到这一点吗?
javascript - Accessing IndexedDB from multiple javascript threads
Overview: I am trying to avoid a race condition with accessing an IndexedDB from both a webpage and a web-worker.
Setup: Webpage that is saving items to the local IndexedDB as the user works with the site. Whenever a user saves data to the local DB the record is marked as "Unsent".
Web-worker background thread that is pulling data from the IndexedDB, sending it to the server and once the server receives it, marking the data in the IndexedDB as "Sent".
Problem: Since access to the IndexedDB is asynchronous, I can not be guaranteed that the user won't update a record at the same time the web-worker is sending it to the server. The timeline is shown below:
- Web-worker gets data from DB and sends it to the server
- While the transfer is happening, the user updates the data saving it to the DB.
- The web-worker gets the response from the server and then updates the DB to "Sent"
- There is now data in DB that hasn't been sent to the server but marked as "Sent"
Failed Solution: After getting the response from the server, I can recheck to row to see if anything has been changed. However I am still left with a small window where data can be written to the DB and it will never be sent to the server.
Example: After server says data is saved, then:
Other notes: There is a sync api according to the W3 spec, but no one has implemented it yet so it can not be used (http://www.w3.org/TR/IndexedDB/#sync-database). The sync api was designed to be used by web-workers, to avoid this exact situation I would assume.
Any thoughts on this would be greatly appreciated. Have been working on it for about a week and haven't been able to come up with anything that will work.
javascript - 在 Firefox 扩展中使用 indexedDB
我无法在 Firefox 扩展中使用 indexedDB 保存数据。我也找不到关于 indexedDB 和 Firefox 扩展的任何信息。
有没有人处理过这个问题?
javascript - 为什么连接到 indexedDB 时从未调用过我的 onupgradeneeded 回调?
我正在尝试使用 IndexedDB 获取一些本地存储的数据。下面我有一个简单的例子,我试图用它来触发 onupgradeneeded 事件
我试图更改版本号,但无论我尝试什么 onupgradeneeded 都不会被调用/触发。任何建议为什么?
欢呼卢卡
javascript - 为 IndexedDB 键生成 UUID?
IndexedDB 的 W3C 规范将密钥生成器定义为:
每次需要密钥时,密钥生成器都会生成一个单调递增的数字 [原文如此]。
现在,(在我看来)IndexedDB(或者,就此而言,任何 HTML5 客户端存储选项:WebSQL、localStorage 等)的常见用例似乎是设计为离线工作的应用程序(与 HTML5 结合使用)应用程序缓存)。
在这种情况下,断开连接的Web 应用程序可能会在其本地数据存储中生成新的对象/记录,这些对象/记录稍后会在与服务器的连接可用时同步到集中式数据库。
此外,多个客户端同步到同一个集中式数据库的任何应用程序通常都需要一种机制来防止 ID 冲突。
UUID(或 GUID)是一个不错的选择,因为它可以在没有任何中央协调的情况下生成唯一的密钥。相比之下,“单调递增的数字”是一个糟糕的解决方案(除非每个客户端都“播种”了一个不太可能与其他用户发生冲突的起始值)。
我发现令人惊讶的是,IndexedDB 规范没有指定(甚至允许将来支持)备用密钥生成器,例如 UUID 生成器。有些人可能会建议答案是根本不使用 IndexedDB 的内置密钥生成器,而是让您的应用程序生成它自己的密钥。
然而,虽然有很多基于 Javascript 的 UUID 生成器可用,但其中许多似乎是基于 Math.random() 的,它在随机性方面具有已知的局限性,因此如果必须使用绝对唯一键,则可能不是一个好的选择保证。
IndexedDB 实现者提供的本机 UUID 生成器(可能)会比应用程序实现/导入的脚本更健壮并且性能更好;有人会想。
那么我在这里错过了什么,还是 W3C IndexedDB 工作组错过了一个机会?
javascript - 在 indexedDB 中存储图像数据
在这一点上,我对这个问题的兴趣主要是理论上的。
我想在本地存储图像(用于 webgl 纹理),例如我已经用来存储网格的 indexedDB。
这可能吗?如果是这样,那怎么办?这是个好主意吗?
javascript - 在触发事件的方法调用之后设置 JavaScript 事件处理程序?
在查看 IndexedDB API 时,我发现了几个在方法调用之后设置的事件处理程序示例,看起来它应该触发事件。例如:
尽管我在 JavaScript 方面做了很多开发,但我很尴尬地说这对我来说看起来很奇怪。我觉得应该在实际的 open() 调用之前设置事件处理程序,但我已经在几个示例中看到了这种模式。有人可以帮我理解这一点吗?
javascript - HTML5 离线存储/Web SQL
我被要求研究移动设备上 Web 表单的离线存储选项(主要是 iPad 上的注册表单,用于大型活动,由于数量庞大,位置连接似乎总是一个问题)。
我想提出的是:
- 一种可以在连接时提交数据,或者在离线时存储的表单。
- 定期检查连接并在可能时提交表单数据。
谁能在这里指出我正确的方向?
谢谢,
克里斯