0

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

Community
  • 1
  • 1
André Bolinhas
  • 157
  • 1
  • 2
  • 10

1 Answers1

0

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


}
André Bolinhas
  • 157
  • 1
  • 2
  • 10