HTML5 IndexedDB 示例


以下函式是用於新增資料的 IndexedDB 示例

function add() {
   var request = db.transaction(["employee"], "readwrite")
   .objectStore("employee")
   .add({ id: "001", name: "Amit", age: 28, email: "demo1@example.com" });
   request.onsuccess = function(event) {
      alert("Amit has been added to your database.");
   };
   request.onerror = function(event) {
      alert("Unable to add data\r
Amit is already exist in your database! ");    } }

在上面,我們在資料庫中添加了以下詳細資訊

const employeeData = [
   { id: "001", name: "Amit", age: 28, email: "demo1@example.com" },
];

更新日期:29-1-2020

193 次瀏覽

開啟你的 職業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.