IndexedDB和异步响应
IndexedDB and asynchronous response
我正在阅读一篇关于IndexedDB的教程,但我有一些疑问。
将您的WebSQL数据库迁移到IndexedDB
看看这个代码
function showAll() {
document.getElementById("ourList").innerHTML = "";
var request = window.indexedDB.open("todos");
request.onsuccess = function(event) {
// Enumerate the entire object store.
var ul = document.createElement("ul");
var db = todoDB.indexedDB.db;
var trans = db.transaction("todo", 'readonly');
var request = trans.objectStore("todo").openCursor();
request.onsuccess = function(event) {
var cursor = request.result;
// If cursor is null then we've completed the enumeration - so update the DOM
if (cursor) {
var li = document.createElement("div");
li.textContent = "key: " + cursor.key + " => Todo text: " + cursor.value.text;
ul.appendChild(li);
cursor.continue();
}
else {
document.getElementById("ourList").appendChild(ul);
}
}
}
}
我每次都会看到,在我对对象调用操作/方法之前,比如这个
var request = trans.objectStore("todo").openCursor();
然后,只有在调用了操作之后,我才设置onsuccess
方法
request.onsuccess = function(event) {
这是怎么回事?一旦返回请求,我如何确保该方法已经在运行,并且我必须设置onsuccess回调?
您是否在问,在定义对象之后,如何为对象定义成功处理程序?如果是这样的话,它就是有效的。(浏览器足够聪明,可以知道,如果在执行打开光标的行到定义处理程序的位置之间的几毫秒内,光标被打开了,那么它应该会自动触发处理程序。
相关文章:
- 如何从SeleniumWebdriver获取异步Javascript响应
- 使用来自不同异步函数的响应创建一个json对象
- 节点.js和表达式:如何在异步操作后返回响应
- 异步表单w/Iframe Target——OnLoad适用于FF、Chrome、IE9,不适用于;无法在IE7中得到响应
- Node.JS-如何识别哪个异步HTTPGET响应在回调中返回数据
- 接收json异步响应的最有效方式
- 如何使用 ajax 或 jquery 读取异步 HTTP (servlet3.0) 响应
- 如何将异步 ajax 响应捕获到变量中
- 函数返回异步响应
- 如何从 angularjs 服务中的异步调用返回响应
- JQuery/Ajax:如何将多个 ajaxes 组合成一个具有响应的异步 ajax
- 节点.js使用异步数据进行响应
- 等待来自异步,量角器,nodejs的响应
- 来自 Azure 的插入异步响应
- 如何处理对循环中发出的多个异步请求(AJAX 调用)的响应
- 节点JS-异步-响应是在执行查询时发送的
- 如何通过异步xmlhttprequest响应设置变量
- 如何在调用异步Web服务响应时将值设置为数组
- 异步序列的响应为false,而它应该为true
- 聚合铁ajax和异步请求(etag同步和响应处理)