发布网友 发布时间:2022-04-09 11:57
共12个回答
懂视网 时间:2022-04-09 16:18
angular.module(‘indexdb‘, []) 2 .factory(‘IndexdbJs‘, [‘$ionicPopup‘,function ($ionicPopup) { 3 4 window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB; 5 window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction; 6 window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange; 7 window.IDBCursor=window.IDBCursor||window.webkitIDBCursor|| window.msIDBCursor; 8 var db={ 9 dbName: ‘aptdb‘, 10 dbVersion: 2046, //用小数会四舍五入 11 dbInstance: {}, 12 13 errorHandler: function (error) { 14 console.log(‘error: ‘ + error.target.error.message); 15 }, 16 17 open: function (func,fail) { 18 var dbContent = window.indexedDB.open(db.dbName, db.dbVersion); 19 dbContent.onupgradeneeded = db.upgrade; 20 dbContent.onerror = db.errorHandler; 21 dbContent.onsuccess = function (e) { 22 db.dbInstance = dbContent.result; 23 db.dbInstance.onerror = fail; 24 func(); 25 }; 26 }, 27 upgrade: function (e) { 28 var _db = e.target.result, names = _db.objectStoreNames; 29 // 此处可以创建多个表 30 var name = "cart"; 31 if (!names.contains(name)) { 32 _db.createObjectStore( 33 name, 34 { 35 keyPath: ‘goodsId‘, 36 autoIncrement:false 37 }); 38 } 39 }, 40 getObjectStore: function (objectStoreName,mode) { 41 var txn, store;mode = mode || ‘readonly‘; 42 txn = db.dbInstance.transaction([objectStoreName], mode); 43 store = txn.objectStore(objectStoreName); 44 return store; 45 }, 46 add: function (objectStoreName,data,success,fail) { 47 db.open(function () { 48 var store, req, mode = ‘readwrite‘; 49 store = db.getObjectStore(objectStoreName,mode), 50 req = store.add(data); 51 req.onsuccess = success; 52 req.onerror=fail; 53 },fail); 54 }, 55 update: function (objectStoreName,data,success,fail) { 56 db.open(function () { 57 var store, req, mode = ‘readwrite‘; 58 store = db.getObjectStore(objectStoreName,mode), 59 req = store.put(data); 60 req.onsuccess = success; 61 req.onerror=fail; 62 },fail); 63 }, 64 getAll: function (objectStoreName,success,fail) { 65 66 db.open(function () { 67 var 68 store = db.getObjectStore(objectStoreName), 69 cursor = store.openCursor(), 70 data = []; 71 72 cursor.onsuccess = function (e) { 73 var result = e.target.result; 74 if (result && result !== null) { 75 data.push(result.value); 76 result.continue(); 77 } else { 78 success(data); 79 } 80 }; 81 cursor.onerror=fail; 82 83 },fail); 84 }, 85 get: function (id,objectStoreName,success,fail) { 86 db.open(function () { 87 var 88 store = db.getObjectStore(objectStoreName), 89 req = store.get(id); 90 req.onsuccess = function (e){ 91 success(e.target.result); 92 }; 93 req.onerror=fail; 94 }); 95 }, 96 // delete是保留字 97 ‘delete‘: function (id,objectStoreName,success,fail) { 98 db.open(function () { 99 var 100 mode = ‘readwrite‘, 101 store, req; 102 store = db.getObjectStore(objectStoreName,mode); 103 req = store.delete(id); 104 req.onsuccess = success; 105 req.onerror=fail; 106 }); 107 }, 108 deleteAll: function (objectStoreName,success,fail) { 109 db.open(function () { 110 var mode, store, req; 111 mode = ‘readwrite‘; 112 store = db.getObjectStore(objectStoreName,mode); 113 req = store.clear(); 114 req.onsuccess = success; 115 req.onerror=fail; 116 }); 117 } 118 }; 119 120 return db; 121 }]); View Code
IndexedDB通用功能封装成angular服务
标签:
热心网友 时间:2022-04-09 13:26
index的意思是:
1.索引; <数>指数; 指示; 标志;
2.给…编索引; 把…编入索引; [经济学]按生活指数调整(工资、价格等);
3.[机械学] 转位;
读音:英[ˈɪndeks] 美[ˈɪnˌdɛks]
例句:
1.Curiously, the word 'gay' does not occur in the index
奇怪的是,gay这个词没有出现在索引当中。
2.She's indexed the book by author, by age, and by illustrator.
她根据作者、年龄和插图画家分别为该书编了索引。
3.The index is the government's chief gauge of future economic activity.
这一指数是*判断未来经济活动的主要依据。
4.The retail price index for September is expected to show inflation edging up to about 10.8 percent.
预计9月份的零售价格指数将显示通货膨胀率已*近10.8%。
index
词性:n. vt. vi.
第三人称单数:indexes
复数:indices
现在分词:indexing
过去式:indexed
过去分词:indexed
热心网友 时间:2022-04-09 14:44
index fund热心网友 时间:2022-04-09 16:19
index在互联网上表示网站的默认主页。热心网友 时间:2022-04-09 18:10
index热心网友 时间:2022-04-09 20:18
词义视语境来判断。热心网友 时间:2022-04-09 22:43
看是在哪种情况下用,有3种意思:索引(书目那种),标志,指数热心网友 时间:2022-04-10 01:24
索引 指针 指数热心网友 时间:2022-04-10 04:22
索引热心网友 时间:2022-04-10 07:37
索引,指数热心网友 时间:2022-04-10 11:08
索引热心网友 时间:2022-04-11 04:00
指数