为了账号安全,请及时绑定邮箱和手机立即绑定

不记录或检索数据

不记录或检索数据

MM们 2021-11-12 16:12:47
出于某种原因,我无法使用 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 databaselet 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);}完整代码在https://jsfiddle.net/m7nx9a3v/这个想法是放置,检索数据并将其填充到表中......提前致谢
查看完整描述

1 回答

?
holdtom

TA贡献1805条经验 获得超10个赞

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!');

        }

      };

    }

参考https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB


查看完整回答
反对 回复 2021-11-12
  • 1 回答
  • 0 关注
  • 145 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信