2017-08-25 40 views
0

該數據庫有toArray方法,如何將數組保存到數據庫(toDB)?Dexie DB:如何將數組保存到數據庫?

+0

我不認爲它會返回一個存儲數組。它將項目的集合放入數組中。反向操作可能是['Table.bulkAdd()'](http://dexie.org/docs/Table/Table.bulkAdd().html) – Redu

回答

0

使用Table.bulkAdd()或Table.bulkPut()。例如:

var db = new Dexie("testdb"); 
db.version(1).stores({friends: 'id,name,age'}); 
db.friends.bulkPut([ 
    {id: 1, name: "Foo", age: 33}, 
    {id: 2, name: "Bar", age: 34} 
]).then(result => { 
    alert ("Successfully stored the array"); 
}).catch(error => { 
    alert ("Error: " + error); 
});