简体   繁体   中英

localForage iterate does not work from JS file

There are 6 keys in the database and I confirmed it by checking it in the browser console.

The following code only loops 3 times and after the condition becomes false, it stops.

localforage.iterate(function (value, key, iterationNumber) {
    console.log(key);
    if (key != lastReminderIdKey) {                            
        //console.log(value);                            
    }
}).then(function (value) {
    console.log('Iteration has completed');
}).catch(function (err) {
    console.log(err);
});

This code was working fine when it was inside the HTML file. Then I moved it to a JS file and the iteration/loop works only partially now. When I move it back to the HTML file, it works alright.

The keys in DB are 1, 2, lastReminderKey, 3, 4, 5 . In console log, when run from the JS file, it prints:

1
2
lastReminderKey
Iteration has completed

What could be the reason for this behaviour?

Chances are you are using different localforage configs in 2 places. Try verify that both localforage instances have exact same set of name , storeName , and driver .

You can inspect these properties on the options object.

const options = localforage.config();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM