1

I have an array of objects and want to insert them in a table but only first one record is inserted and rest are not

data.forEach(function(obj){         
    mydb.tasks.add(obj);
    mydb.saveChanges(); 
});

here is what I am actually doing

data.forEach(function(obj){

    mydb[table].filter("it._id == '"+obj._id+"'")
    .toArray( function(objs){

        if(!objs.length){
            mydb[table].add(obj);
            mydb.saveChanges();  
        }

    });         

}); 
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

1

Move savechanges out of the loop or use our other api called itemstore api

Gabor Dolla
  • 2,680
  • 4
  • 14
  • 13
  • i tried it by taking savechanges out of loop but still only first obj is stored, is there a way to add more than one records simultaneously ? like mydb[table].add(all_objs); – Ubadah Arain Nov 06 '13 at 18:14