admin管理员组文章数量:1392105
I am trying to implement this example.
Everything works fine until I attempt to delete a certain item.
Using this:
request.onupgradeneeded = function(event) {
console.log("upgrade", event);
db = event.target.result;
console.log("db", db);
if (!db.objectStoreNames.contains("chatBot")) {
var objectStore = db.createObjectStore("chatBot", {keyPath: "timeStamp", autoIncrement: true});
}
};
and setting up the deletion:
btnDelete.addEventListener("click", function() {
var id, transaction, objectStore, request;
id = document.getElementById("txtID").value;
console.log("id", typeof id);
transaction = db.transaction("people", "readwrite");
objectStore = transaction.objectStore("people");
request = objectStore.delete(id);
request.onsuccess = function(evt) {
console.log("deleted content");
};
}, false);
There is no problem adding items to the indexedDB but for some reason I can't figure out why it can't delete the items.
The id
is a string and the objectStore.delete(id)
is the correct implementation.
Here is a pastebin of the example
Using Firefox 18
I am trying to implement this example.
Everything works fine until I attempt to delete a certain item.
Using this:
request.onupgradeneeded = function(event) {
console.log("upgrade", event);
db = event.target.result;
console.log("db", db);
if (!db.objectStoreNames.contains("chatBot")) {
var objectStore = db.createObjectStore("chatBot", {keyPath: "timeStamp", autoIncrement: true});
}
};
and setting up the deletion:
btnDelete.addEventListener("click", function() {
var id, transaction, objectStore, request;
id = document.getElementById("txtID").value;
console.log("id", typeof id);
transaction = db.transaction("people", "readwrite");
objectStore = transaction.objectStore("people");
request = objectStore.delete(id);
request.onsuccess = function(evt) {
console.log("deleted content");
};
}, false);
There is no problem adding items to the indexedDB but for some reason I can't figure out why it can't delete the items.
The id
is a string and the objectStore.delete(id)
is the correct implementation.
Here is a pastebin of the example
Using Firefox 18
Share Improve this question edited Jan 15, 2013 at 4:05 user1460015 asked Jan 15, 2013 at 2:25 user1460015user1460015 2,0033 gold badges29 silver badges37 bronze badges1 Answer
Reset to default 6Since you are using autoIncrement key, the key is generated by the user agent. In FF and Chrome, it is integer starting with 1. If you give valid key and convert your id
to integer, your code run fine. I tested in both FF and Chrome (dartium). '1'
and 1
are different keys according to IndexedDB API key definition.
Another issue IndexedDB API design. The delete methods always return to success event handler with undefined
as result whether given key was deleted or not. So it is very difficult to debug. I think it should return number of deleted records at least.
[Edit] mod code: http://pastebin./mLpU0VfP
[Edit... also] Notice the +
which converts the string
to an integer
request = db.transaction("people", "readwrite").objectStore("people").delete(+id);
本文标签: javascriptDeleting item in IndexedDB while using autoIncrementStack Overflow
版权声明:本文标题:javascript - Deleting item in IndexedDB while using autoIncrement - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744780050a2624653.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论