我正在尝试将localForage与localForage-cordovaSQLiteDriver一起使用来在cordova应用程序中设置持久存储。它不起作用,我不断将以下条目记录到控制台:
我不确定我localforage
是否正确理解了生命周期。这就是我所拥有的:
// 1) setup cordova SQL lite driver
localforage.defineDriver(window.cordovaSQLiteDriver).then(function() {
// 2) set preferred driver order
return localforage.setDriver([
window.cordovaSQLiteDriver._driver, // <-- prefer cordovaSQLiteDriver
localforage.INDEXEDDB,
localforage.WEBSQL,
localforage.LOCALSTORAGE
]);
})
.then(function() {
// 3) wait for localForage to be ready
return localforage.ready();
})
.then(function() {
// 4) create a globally scoped app database
window.appStorage = localforage.createInstance({
version: 1.0,
size: 52428800, // 50mb
name: 'my-app-name',
storeName: 'setup'
});
// 5) check if we're using cordova sql lite
if (localforage.driver() !== window.cordovaSQLiteDriver._driver) {
console.warn('Not using cordovaSQLiteDriver.');
}
// 6) write something
return appStorage.setItem('message', 'It worked!'); // <-- only it doesn't
})
.then(function() {
// 7) get the value back out of the database
return appStorage.getItem('message');
})
.then(function(message){
// 8) write the value to the console
console.log(message);
});
在我看来它应该是打印它工作!到控制台。