在indexedDB中添加数据时,DOM IDBDatabase异常5 [英] DOM IDBDatabase Exception 5 when adding data in indexedDB

查看:174
本文介绍了在indexedDB中添加数据时,DOM IDBDatabase异常5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的对象结构是这样的:

My object structure is like this:

var test={
        "id":"A",
        "ChanName":"Discovery",
        "LCN":10
        };

这是创建对象库的代码段:

This is the snippet that creates the object store:

var objectStore = db.createObjectStore('Dat', { keyPath:'test.id',autoIncrement: false});

var trans = db.transaction(["Dat"], webkitIDBTransaction.READ_WRITE);
         var store = trans.objectStore("Dat");
         var request=store.put(test);

当我尝试添加测试对象时,出现此异常DATA_ERR:DOM IDBDatabase异常5.我正在使用chrome 18进行测试.创建对象存储很好,但无法添加数据

When i try to add the test object i get this exception DATA_ERR: DOM IDBDatabase Exception 5. Please can you advice on what is wrong here? I am using chrome 18 to test this.The creation of object store is fine,but not able to add data

推荐答案

向操作提供的数据不符合要求时,将引发IndexedDB异常5."通常,这是因为,例如,当您提供缺少该属性的对象时,便添加了索引.

An IndexedDB Exception 5 is thrown when the "Data provided to an operation does not meet requirements." This is typically because you've added an index, for example, while providing an object missing that attribute.

在这里,您的test对象似乎与您指定为键路径的对象不匹配.

Here, it appears your test object doesn't match what you've specified as a keypath.

如果要id作为键,则createObjectStore必须像这样:

If you want id as a key your createObjectStore would have to be like this:

var objectStore = db.createObjectStore('Dat', { keyPath:'id',autoIncrement: false});

作为另一个示例,或者,使用keyPath保持原样,您的test对象将需要看起来像这样,以免引发此错误:

As a further example, alternatively, with your keyPath as is your test object would need to look like this to not throw this error:

var test={
 test: { "id":"A" },
 ChanName:"Discovery",
 LCN:10
};

这篇关于在indexedDB中添加数据时,DOM IDBDatabase异常5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆