DOM IDBDatabase Exception 5 when adding data in indexedDB

∥☆過路亽.° 提交于 2020-01-24 15:49:04

问题


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);

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


回答1:


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.

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

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

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

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
};


来源:https://stackoverflow.com/questions/10509546/dom-idbdatabase-exception-5-when-adding-data-in-indexeddb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!