由于某种原因,我无法使用IndexedDB方法检索和/或放置任何数据...代码是否错误或缺少某些内容?
我已经放置了几个console.log,并且我已经添加或尝试添加新值,但是说已经添加了它们(或者至少是成功消息弹出窗口,但是没有任何结果显示在控制台日志中……) >
let newDataLine = [{ name: name.value}];
let transaction = db.transaction( ["permit"], "readwrite");
transaction.oncomplete = function() {
statusText.textContent = 'Something was just added';
console.log('-------transaction.oncomplete----------')
console.log(objectStore);
// update the display of data to show the newly added item, by running displayData() again.
displayData();
};
transaction.onerror = function() {
status.textContent = 'Error reading/writing data from/into db error ' + transaction.error;
}
// call an object store that's already been added to the database
let objectStore = transaction.objectStore("permit");
let objectStoreRequest = objectStore.add(newDataLine[0]);
objectStoreRequest.onsuccess = function(event) {
statusText.textContent = 'New permit was just added';
console.log('-------objectStoreRequest.onsuccess----------')
console.log(objectStore);
}
想法是将数据放置,检索并填充到表中...在此先感谢
出于某种原因,我无法使用IndexedDB方法检索和/或放置任何数据...代码是否错误或缺少某些内容?我已经放置了几个console.log,并且已经添加了...
function displayData() {
let objectStore = db.transaction('permit').objectStore('permit');
objectStore.openCursor().onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
dataLine.innerHTML+= '<tr><td>'+cursor.value.name+'</td><td class="buttons"></td></tr>';
console.log(
'Name for key ' + cursor.key + ' is ' + cursor.value.name
);
cursor.continue();
} else {
console.log('No more entries!');
}
};
}