Changes

Jump to navigation Jump to search
m
no edit summary
Line 1: Line 1: −
console.log("~");
   
console.log("~");
 
console.log("~");
   Line 26: Line 25:  
     // store.put(John);
 
     // store.put(John);
 
     // store.put(Bob);
 
     // store.put(Bob);
   
+
     var Pete = {id: 11345, name: {first: "Pete", last: "Rock"}, age: 42
 
+
     store.put(Pete);
    // Query the data
+
    recordUpdate(["Pete", "Rock"], phoneNumber, '+674316');
     var getJohn = store.get(12345);
+
    // Query the data 
    var getBob = index.get(["Smith", "Bob"]);
  −
 
  −
     getBob.onsuccess = function() {
  −
      console.log("updating");
  −
      getBob.result.phone = '+312';  // => "Bob"
  −
      store.put(getBob.result);
  −
 
  −
      getBobAgain = index.get(["Smith", "Bob"]);
  −
          getBobAgain.onsuccess = function() {
  −
            console.log(getBobAgain.result.phone);  // => "Bob"
  −
          };
  −
 
   
  };
 
  };
 
      
 
      
 +
    // Close the db when the transaction is done
 +
    tx.oncomplete = function() {
 +
        db.close();
 +
    };
 +
}
    +
function recordUpdate(record, field, value){
    +
    var getRecord = index.get(record);
   −
     // Close the db when the transaction is done
+
     getRecord.onsuccess = function() {
    tx.oncomplete = function() {
+
      console.log("updating");
        db.close();
+
      getRecord.result.field = value;  // => "Bob"
 +
      store.put(getRecord.result);
 +
      checkrecord(record, field)
 
     };
 
     };
 +
}
 +
 +
function checkRecord(record, field) {
 +
      checkRecord = index.get(record);
 +
      checkRecord.onsuccess = function() {
 +
        console.log(getRecordAgain.result.phone);  // => "Bob"
 +
      };
 
}
 
}
530

edits

Navigation menu