首页 新闻 赞助 找找看

indexDB问题:evt.target.result为null?

0
悬赏园豆:50 [已解决问题] 解决于 2012-04-16 10:07

我的代码如下:

var indexedDB = window.msIndexedDB;

adsageIDB = {};
adsageIDB.db = null;

adsageIDB.onerror = function (e) {
    console.log(e);
};

adsageIDB.open = function () {
    var request = indexedDB.open("adsageIDB", 1);

    request.onsuccess = function (evt) {
        adsageIDB.db = evt.target.result;
        var db = adsageIDB.db;
        if (db.objectStoreNames.contains("todo")) {
            db.deleteObjectStore("todo");
        }
        var store = db.createObjectStore("todo",{ keyPath: "adsid" });

    };
    request.onerror = function (evt) {
        console.log("Database error code:" + evt.target.errorCode);
    };
}

环境是win8下的 javascript metro app,运行后 adsageIDB.db 一直为空,请问是哪儿写的有问题?

artwl的主页 artwl | 专家六级 | 园豆:16736
提问于:2012-04-10 17:44
< >
分享
最佳答案
0
adsageIDB.open()执行了吗?没有看到调用代码呀
收获园豆:50
玉开 | 大侠五级 |园豆:8822 | 2012-04-10 18:24

调用了,在其他方法中调用的

artwl | 园豆:16736 (专家六级) | 2012-04-10 18:55

谢谢你的回复,找到原因了,是onsuccess 这个方法是异步的,没有执行导致的

artwl | 园豆:16736 (专家六级) | 2012-04-16 10:07
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册