Ruben Teixeira
Ruben Teixeira

Reputation: 574

IndexedDB. How to update records as cursor moves

In a synchronization method I´m opening a cursor and sending Ajax posts to server. I need at the same time to set the record "flag" to synchronized.

var transaction = db.transaction([STORE],IDBTransaction.READ_WRITE);
transaction.objectStore(STORE).openCursor().onsuccess = function(e){
    var cursor = e.target.result;
    if(cursor){
        if (cursor.value.flag == "0") {

            //sync method                               
            cursor.update(cursor.value.flag = "1")  // not working

        };              
        cursor.continue();
    };
}; 

How can I do this?

Upvotes: 2

Views: 1951

Answers (1)

Kyaw Tun
Kyaw Tun

Reputation: 13131

try:

cursor.value.flag = "1";
cursor.update(cursor.value);

Upvotes: 9

Related Questions