按ID更新IndexedDB [英] IndexedDB update by id
本文介绍了按ID更新IndexedDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试更新我的indexedDB记录,但出现此错误
I'm trying update my indexedDB records but I get this error
DataError:提供给操作的数据不符合要求. 源文件
DataError: Data provided to an operation does not meet requirements. Source File
我已经尝试过此但没有用
这是我的功能:
function updNotes(text, timestamp, blob)
{
var obj = {text: text, timestamp: timestamp};
if (typeof blob != 'undefined')
obj.image = blob;
store = getObjectStore("notes", 'readwrite');
objKeyRange = IDBKeyRange.only(+objtoedit);
req = store.openCursor(objKeyRange);
req.onsuccess = function(evt){
var cursor = evt.target.result;
console.log(cursor.key);
//do the update
var objRequest = cursor.update(obj);
objRequest.onsuccess = function(ev){
console.log('Success');
};
objRequest.onerror = function(ev){
console.log('Error');
};
};
req.onerror = function(evt){
console.log('Error');
};
任何人都可以帮助我解决此问题吗?
Anyone can help me to fix this ?
最诚挚的问候
推荐答案
我知道如何做到这一点. 此功能解决了我的问题.
I figure out how to do this. This function solved my problem.
function updNotes(id, text, timestamp, blob)
{
console.log(id);
store = getObjectStore("notes", 'readwrite');
req = store.get(+id);
req.onsuccess = function(evt){
var data = evt.target.result;
data.text = text;
data.timestamp = timestamp;
if (typeof blob != 'undefined')
data.image = blob;
//do the update
var objRequest = store.put(data);
objRequest.onsuccess = function(ev){
console.log('Success in updating record');
};
objRequest.onerror = function(ev){
console.log('Error in updating record');
};
};
req.onerror = function(evt){
console.log('Error in retrieving record');
};
}
这篇关于按ID更新IndexedDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文