0

我正在使用http://nparashuram.com/jquery-indexeddb/此处提供的JQuery IndexedDB 插件。以下是我在 objectstore project_created上迭代的代码。当我运行此代码时,会在迭代objectstore task_created之前提醒ss。但从逻辑上讲,只有在迭代objectstore task_created之后才应该提醒ss

$.indexedDB("sl_task_tracker").objectStore("project_created").each(function(elem){
        var count_tasks=0;
        $.indexedDB("sl_task_tracker").objectStore("task_created").each(function(item){
            if(item.value.project_id==elem.key)
                count_tasks++;
        });

        alert("ss");
});
});
4

2 回答 2

1

我相信这是因为 IndexedDB 使用了异步 API。与 IndexedDB 相关的一切都在“另一个线程”中完成,以便不阻塞主线程(这样网站就不会看起来是固定的)。

我不知道这个插件,但你应该检查你是否可以将“onSuccess”函数传递给你的任务,这样你就可以指定任务完成后会发生什么。

有关您正在使用的插件的更多信息,您可以随时在他的 github 页面上询问开发人员:https ://github.com/axemclion/jquery-indexeddb

(抱歉我的技术英语不好,请随时用更易于理解的语言进行编辑)

于 2012-09-14T07:31:23.530 回答
0

我编写了一个小的 jquery 插件(仍然非常 alpha)来缓解异步和其他令人困惑的 API:

https://github.com/ameyms/jquery-indexeddb

我试图保持 API 超级简单:

//Define and initialize an IndexedDB ...
var db = $.idb({
                    name:'foobar', 
                    version: 2,
                    drop: stores_to_be_deleted,
                    stores:list_of_stores
                });

// ... Add objects to a store
db.put(items, 'into_store').done(onsuccess);

//.. And delete objects from a store
db.remove('from_store', conditionFunc).done(onremoval);

//.. And not to forget fetching objects from a store
db.select('from_my_store', conditionFunc).done(function (items){

    console.log(items)
});

希望你喜欢!

于 2013-09-23T08:45:21.137 回答