Search code examples
promisedexie

Dexie toArray() Promise


I need to create and consume an array from Dexie ordeBy Promise

var list = [];
const ms = wmsLocalDb.table1.orderBy("index").toArray();
ms.each(m => list.push(m)).then(
   //When list is complete I want to consume 
   for (var i = 0; i < list.length; i++) { 
       //something
   }
);

But i cannot read list array. Best regards Ingd


Solution

  • You want something along the following lines :

    wmsLocalDb.table1.orderBy("index").toArray()
    .then(list => {
        list.forEach(item => {
           //something
        });
    })
    .catch(error => {
        // handle error
    });