0
这是我的代码片段:AngularJS:从工厂,如何调用另一个函数在一个周期
_service.factory('$opSQL', [ '$rootScope', '$cordovaSQLite',
function($rootScope, $cordovaSQLite){
var db = $cordovaSQLite.openDB( "my.db");
var dbURL = dbConfig.remoteUrl;
var opSQL = {
deleteRow : function(row) {
var strQuery = "DELETE FROM UpdateTo WHERE id = ? ;";
$cordovaSQLite.execute(db, strQuery, [row.id])
.then(
function(res) { console.log (JSON.stringify(row.id)); },
function (err) { console.log (JSON.stringify(err)); });
},
sendToServer : function(tmp) {
// where tmp = [ { "id":1, "other"="..." }, { "id":2, "other"="..." } ... ]
for(x in tmp)
{
opSQL.deleteRow(tmp[x]);
}
}
}
return opSQL;
}
]);
我认为这个问题是SQLite中执行异步因为查询完成成功,但在控制台我只读取列表的第一个ID。
如何解决这个问题?
您只输出'row.id'。你的期望是什么? – lex82
当我调用fn“sendToServer”时,我期待看到所有循环的id,但输出总是关于列表的第一个元素。 – Danilo
我建议你进一步缩小问题的范围。多久调用deleteRow()?你可以在那里放置一些调试输出。 – lex82