I need to insert x rows into the DB. Here is my code:
dataFactory.insertData = function (responseData)
{
var q = $q.defer();
var rows = 0;
$.each(responseData, function (index, value)
{
//... prepare data...
$cordovaSQLite.execute(db, query).then(function (res)
{
rows += 1;
}, function (err)
{
console.error(err);
});
});
q.resolve(rows);
return q.promise;
};
How can I wait for all inserts to finish before calling resolve? I believe that the q.promise will get resolved before all rows are inserted.
Aucun commentaire:
Enregistrer un commentaire