美文网首页
indexDB根据游标索引

indexDB根据游标索引

作者: 刘佳季 | 来源:发表于2020-11-08 14:27 被阅读0次

    const db = new IndexDB('offlLineDB', getIndexedDBVersionOfNum()) // 数据库名  数据库版本

    db.getIndexDataByCursor('basic_DB_assembly', keyWord, code)

    --------------------------------------------------------------------------------------------

    getIndexDataByCursor(storeName, storeIndex, storeKey) {

        const si = storeIndex

        const sk = storeKey

        return new Promise((resolve, reject) => {

          const request = indexedDB.open(this.dbName, this.version)

          request.onerror = function() {

            reject('IndexedDB数据库打开错误,请联系管理员。')

          }

          request.onsuccess = function(event) {

            const IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange

            const onlyKeyRange = IDBKeyRange.only(sk)

            const result = event.target.result

            const objectStore = result.transaction(storeName).objectStore(storeName).index(si).openCursor(

              onlyKeyRange)

            const dataList = []

            objectStore.onsuccess = function(event) {

              const cursor = event.target.result

              if (cursor) {

                dataList.push(cursor.value)

                cursor.continue()

              } else {

                resolve(dataList)

              }

            }

          }

        })

      }

    相关文章

      网友评论

          本文标题:indexDB根据游标索引

          本文链接:https://www.haomeiwen.com/subject/agvlbktx.html