0
我需要在數據庫中插入x行。這裏是我的代碼:在sqlite插入角度等待諾言
dataFactory.insertData = function (responseData)
{
var q = $q.defer();
var rows = 0;
$.each(responseData, function (index, value)
{
var query = "insert or ignore into ...";
$cordovaSQLite.execute(db, query).then(function (res)
{
rows += 1;
}, function (err)
{
console.error(err);
});
});
q.resolve(rows);
return q.promise;
};
如何等待所有插入完成後再調用解決?我相信在插入所有行之前,q.promise會得到解決。
我認爲每個應用檢查裏面像if(rows === responseData.length)意味着所有插入db的數據。 –
那好,但不是問題。所有插入完成後,我都想解決承諾。我認爲在插入所有行之前會解析該解析。 –
解決上述檢查中的承諾。 –