0

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

“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();
            }
        );
    },
4

1 回答 1

0

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

于 2015-10-24T15:57:33.473 回答