问题
I'm trying update my indexedDB records but I get this error
DataError: Data provided to an operation does not meet requirements. Source File
I already tried this but don't worked
This is my function:
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 ?
Best regards
回答1:
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');
};
}
来源:https://stackoverflow.com/questions/14800180/indexeddb-update-by-id