JavaScript执行超过了超时javascript

时间:2012-11-06 14:47:13

标签: javascript sqlite settimeout

当我执行此功能时,它会显示以下错误:

“JavaScript执行超出超时”我如何通过使用settimeout()或什么来解决这个问题?

我从json文件中检索3000行。

 applyChanges_PhrasesTypes: function(employees, callback) {

            //alert("fonction apply chamges est lancer PhrasesTypes");

          this.db.transaction(
                function(tx) {
                    var l = employees.length;
                    var sql =
                        "INSERT OR REPLACE INTO PhrasesTypes (IdPhrase, IdPhraseES, IdRubrique, IdTypeTravauxAffichage, Phrase, AidePhrase, AvertissementPhrase,OrdrePhrase,QuotationParDefaut,Published) " +
                        "VALUES (?,?,?,?,?,?,?,?,?,?)";
                    //alert('Inserting or Updating in local database:  PhrasesTypes');
                    var e;
                    for (var i = 0; i < l; i++) 
                    {
                        e = employees[i];
                        log(i);
                        //log("Ligne  "+ i +"  est inserer de id PhrasesTypes = "+e.IdPhrase);
                        var params = [e.IdPhrase, e.IdPhraseES, e.IdRubrique, e.IdTypeTravauxAffichage, e.Phrase, e.AidePhrase, e.AvertissementPhrase,e.OrdrePhrase,e.QuotationParDefaut,e.Published];
                        tx.executeSql(sql, params);
                    }
                    log('sync_PhrasesType shronization terminée avec (' + l + ' items sync_PhrasesTypeshronié)');
                },
                this.txErrorHandler_PhrasesTypes,
                function(tx)
                {
                    callback();
                }
            );
        }

@lgor:这是我的代码,但只有2000插入行,并以错误终止

JavaScript执行超出了超时javascript

 InsertPortion: function(tx)
    {
     var l = Math.min(gEmployees.length, gIter + 300);

     log('aaaaaaaaaaaaaaaaaaaaaaaa---'+l)

     for (; gIter<l ; gIter++)
                {
         log('do insert here'); 
          var sql =
             "INSERT OR REPLACE INTO PhrasesTypes (IdPhrase, IdPhraseES, IdRubrique, IdTypeTravauxAffichage, Phrase, AidePhrase, AvertissementPhrase,OrdrePhrase,QuotationParDefaut,Published) " +
             "VALUES (?,?,?,?,?,?,?,?,?,?)";
         //alert('Inserting or Updating in local database:  PhrasesTypes');
                var e;            
             e = gEmployees[gIter];
             log(gIter);
             //log("Ligne  "+ i +"  est inserer de id PhrasesTypes = "+e.IdPhrase);
             var params = [e.IdPhrase, e.IdPhraseES, e.IdRubrique, e.IdTypeTravauxAffichage, e.Phrase, e.AidePhrase, e.AvertissementPhrase,e.OrdrePhrase,e.QuotationParDefaut,e.Published];
             tx.executeSql(sql, params);

                  }

                if (gIter < gEmployees.length)
                {
                    log('sync_PhrasesType shronization terminée avec (' + gIter+ ' items sync_PhrasesTypeshronié)');
                    setTimeout(dao3.InsertPortion(tx), 100);
                } 
                else
                {
                   gEmployees = null; 
                   gIter = 0;
                }

   },




applyChanges_PhrasesTypes: function(employees, callback) {

        //alert("fonction apply chamges est lancer PhrasesTypes");

      this.db.transaction(
            function(tx)
            {
                gIter = 0;
                gEmployees = employees;

                dao3.InsertPortion(tx);

            },
            this.txErrorHandler_PhrasesTypes,
            function(tx)
            {
                callback();
            }
        );
    },

1 个答案:

答案 0 :(得分:0)

考虑将代码中的循环转换为异步调用。 看看https://github.com/caolan/async