删除方法不适用于索引数据库HTML5 ...它会返回成功,但记录不会被删除 [英] Delete method is not working for Indexed DB HTML5... It returns success but the record is not deleted
问题描述
另一个我使用Desktop Chrome获得HTML5索引数据库的问题是,我无法从对象存储中删除记录。 onsuccess事件被触发,但记录仍然存在......我的ID是一个时间戳,仅仅是因为我想更快地实现工作应用程序。我硬编码它,但它仍然无法正常工作。这真的很奇怪,因为onsuccess事件被触发了......
Another problem that I am getting with Indexed DB for HTML5, using Desktop Chrome, is that I can not delete a record from an object store. The onsuccess event is triggered but the record is still there... My ID is a time stamp just because I wanted to achieve a working app faster. I hardcoded it but it still does not work. It is really strange because the onsuccess event is triggered...
执行的代码部分如下:
try
{
try {
if (localDatabase != null && localDatabase.db != null)
{
var store = localDatabase.db.transaction("patients", "readwrite").objectStore("patients");
var request = store.delete("1384882073632");
request.onsuccess = function(event)
{
alert("Patient deleted from DB");
update_patients_stored();
aux1.value = "";
aux2.value = "";
aux3.value = "";
aux4.value = "";
};
request.onerror = function(event)
{
alert("Error deleting");
};
}
}
catch(e)
{
alert(e);
}
预先感谢您!
推荐答案
我发现了一个类似的问题。非删除行为,但onsuccess事件发射。尽管 w3 IDBObjectStore.delete规范声明了密钥参数可以是任何类型,我解决了它迫使参数转换为数字:
I've found a similar problem. Non-deleting behaviour but onsuccess event fired. Despite w3 IDBObjectStore.delete specification states key parameter can be of any type, I solved it forcing the parameter conversion to number:
//My version
//I use default autoIncrement for keys
var objectStore = db.createObjectStore(objStoreName,{autoIncrement:true});
//appears to need a number for the key (but retrieved from HTML as string
var request = db.transaction(objStoreName,'readwrite')
.objectStore(objStoreName)
.delete(Number(parent.id));
request.onsuccess = function(e) {
console.log("element deleted"); //sadly this always run :-(
}
所以你的第四行应该是:
So your line four should be:
var request = store.delete(1384882073632); //integer id
//rather than (WRONG):
//var request = store.delete("1384882073632"); //WRONG! string id
尝试过:
Chromium - Manjaro Linux上的版本50.0.2661.94(64位)
Chromium -- Version 50.0.2661.94 (64-bit) on Manjaro Linux
尚未在其他环境或浏览器上进行测试,但猜猜这是你的问题。
Have not tested it on other environments or browsers, but guess that's your problem.
这篇关于删除方法不适用于索引数据库HTML5 ...它会返回成功,但记录不会被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!