0
我在phonegap中有一個函數,用於生成足球裝置。Cordova和executeSQL undefined
該函數將組的id放入一個對象中,然後循環輸入到WebSQL數據庫中。
我遇到的問題是executeSQL函數多次插入最後一次迭代,而不是每次迭代。
對象:
[[{"home":3,"away":"--ghost--"},{"home":2,"away":1}],[{"away":1,"home":"--ghost--"},{"away":3,"home":2}],[{"away":2,"home":"--ghost--"},{"away":1,"home":3}]]
功能:
for (var i = 0; i < roundarray.length; i++) {
for (var n = 0; n < roundarray[i].length; n++) {
var home = roundarray[i][n]['home'];
var away = roundarray[i][n]['away'];
if (home != '--ghost--' && away != '--ghost--') {
console.log('home: '+home+', away: '+away+', league: '+league);
db.transaction(
function(tx) {
insert_fixture(tx, home, away, league);
}
);
}
}
}
}
插入功能:
function insert_fixture(tx, home, away, league) {
tx.executeSql('INSERT INTO games (gameLeague, gameHome, gameAway) VALUES (?,?,?)', [league,home,away],
function(tx, rs) {
console.log('home: '+home+', away: '+away+', league: '+league);
}, errorCB);
}
的控制檯輸出:
2014-09-01 21:09:36.689 LoungeMode[2010:792512] [[{"home":3,"away":"--ghost--"},{"home":2,"away":1}],[{"away":1,"home":"--ghost--"},{"away":3,"home":2}],[{"away":2,"home":"--ghost--"},{"away":1,"home":3}]]
2014-09-01 21:09:36.690 LoungeMode[2010:792512] home: 2, away: 1, league: 1
2014-09-01 21:09:36.691 LoungeMode[2010:792512] home: 2, away: 3, league: 1
2014-09-01 21:09:36.691 LoungeMode[2010:792512] home: 3, away: 1, league: 1
2014-09-01 21:09:36.725 LoungeMode[2010:792512] home: 3, away: 1, league: 1
2014-09-01 21:09:36.737 LoungeMode[2010:792512] home: 3, away: 1, league: 1
2014-09-01 21:09:36.753 LoungeMode[2010:792512] home: 3, away: 1, league: 1
正如您所看到的,前3個控制檯日誌是應該發生的事情,而最後3個是實際發生的事情。
任何想法?