ydn.db - 不能从IndexedDB得到get()值

时间:2013-10-24 23:44:05

标签: javascript indexeddb

使用http://dev.yathit.com/index/downloads.html

中的ydn.db-isw-core-e-qry-dev-raw.js

当我执行以下操作时,我的控制台将显示预期的输出

var db = new ydn.db.Storage('storage');
var id = 1234;
db.put('store-name', {foo: 'bar'}, id);
db.get('store-name', id).done(function(record) {
    console.log("record", record);
});

record Object {foo: "bar"}

但是,如果我省略put()我的控制台返回undefined

var db = new ydn.db.Storage('storage');
var id = 1234;
db.get('store-name', id).done(function(record) {
    console.log("record", record);
}); 

record undefined

如果我使用Chrome的开发人员工具,我可以在我的Resources / IndexedDB中看到记录

为什么不能检索记录?

1 个答案:

答案 0 :(得分:1)

看起来-raw格式只适用于完整的repo和运行构建过程,ant deps尝试使用开发构建-dev

事实证明,您正在使用自动架构。在db.get运行时,数据库未连接,因此您必须等待连接准备如下:

var db = new ydn.db.Storage('storage');
db.onReady(function() {
    var id = 1234;
    db.get('store-name', id).done(function(record) {
        console.log("record before", record);
    });
    db.put('store-name', {foo: 'bar'}, id);
    db.get('store-name', id).done(function(record) {
        console.log("record after", record);
    });
})