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)
}
}
}
})
}
网友评论