简体   繁体   English

事务回调多次触发

[英]Transaction callback fired multiple times

I've ran into some very strange behaviour of my app today: I've got this function to create The tables, and then, when succeeded, going on in the code. 今天我的应用程序遇到了一些非常奇怪的行为:我有这个函数来创建表,然后,当成功时,继续在代码中。

db.transaction(function (tx) {
    tx.executeSql('CREATE TABLE IF NOT EXISTS newsDetail(id unique, title, text, created, createdTS, imageSmall, imageBig, facebook, gameNumber)');
    tx.executeSql('CREATE TABLE IF NOT EXISTS lastModified(id unique, ts)');
    tx.executeSql('CREATE TABLE IF NOT EXISTS teams(pos unique, name, games, gd, points, s, snv, gl, glo, goals)');
    tx.executeSql('CREATE TABLE IF NOT EXISTS players(number unique, name, nickname, birthdate, height, married, children, profession, clubs, position, image)');
    tx.executeSql('CREATE TABLE IF NOT EXISTS games(id unique, home, away, score, date, shortDate)');
    tx.executeSql('CREATE TABLE IF NOT EXISTS galleryCategories(id unique, name, date, thumb, ordering)');
    tx.executeSql('CREATE TABLE IF NOT EXISTS galleryImages(id unique, url, description, catid, ordering)');
    tx.executeSql('CREATE TABLE IF NOT EXISTS videos(id unique, url, title, image)');
}, errorCB, function () {
    loadData('newslist', createNewslist, true);
    loadData('refresh', loadNewOnes, true);
});

The Problem now is, that the Succes Callback function is called 8 times. 现在的问题是,Succes回调函数被调用了8次。 Why is that? 这是为什么? I've been using this code for a few months now and never had this problem before. 我已经使用这个代码几个月了,从来没有遇到过这个问题。 Has anybody ever ran into something similair yet? 有没有人碰到类似的东西呢? Any help is appreciated. 任何帮助表示赞赏。

Likely, you added some code that calls that function several times. 可能,你添加了一些调用该函数几次的代码。 What can happen is that since that function is asynchronous, if you loop through it or run code that continously call that function, that code will not block and wait for your function to finish executing. 可能发生的是,由于该函数是异步的,如果您遍历它或运行连续调用该函数的代码,该代码将不会阻塞并等待您的函数完成执行。 Instead it get's called multiple times without knowing why it's happening. 相反,它被多次调用而不知道它为什么会发生。

Did you happen to write tests to surround the issue so you knew what was being broken? 你碰巧写了测试来围绕这个问题,所以你知道什么被打破了吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM