我是 IndexedDB 的新手,到目前为止,我已经在数据存储的值部分存储了一个 JSON 字符串。
我这样存储:
function createDB() {
customerData = [];
for (i = 0; i < 100000; i++) {
customerData.push({ id: i, add1: "add1_" + i, add2: "add2_" + i, custName: "ted_" + i });
}
var request = window.indexedDB.open("Customer", 1);
request.onsuccess = function (e) {
request = e.target.result;
alert("database created");
};
request.onupgradeneeded = function (e) {
var db = e.target.result;
var store = db.createObjectStore("cust", { keyPath: "id" });
var jsonIndex = store.createIndex("by_key", "id", { unique: true });
var jsonStr = JSON.stringify(customerData);
var request = store.put({ id: "1", json: jsonStr });
};
};
谁能告诉我如何解码这个 JSON 并将其读入 HTML 页面?