2014-02-18 2 views
0

특정 배열에서 for 루프를 쿼리하려고합니다. 그러나 배열의 첫 번째 요소 만 저장합니다. 나는 console.log()를 보았고, 실행을 위해 각각 1로 1을 되 돌렸다. 당신이 내 데이터베이스 location이있는 유일한 일을 볼 수SQLite Phonegap : 루프 오류 쿼리

define(['require'], function(require) { 
    "use strict"; 
    var Backbone = require('backbone'); 

    return Backbone.View.extend({ 
     render: function() { 
      $('#content').fadeOut(200, function() { 
       $(this).load('views/sync.html', function() { 
        $(this).trigger('create'); 
        var preMadeLoc = [ 
         ['L12', 'BALBALAN', 'KALINGA', 'Mountanious', '3rd', 54269, 12082, 0.22, 143201000], 
         ['L8', 'AGUINALDO ', 'IFUGAO ', 'Mountainous', '2nd', 53805, 18610, 0.35, 142708000], 
         ['L7', 'ALFONSO', 'LISTA', 'IFUGAO', 'Mountainous', '3rd', 34746, 28410, 0.82, 142707000], 
         ['L11', 'ASIPULO', 'IFUGAO', 'Mountainous', '5th', 18287, 14403, 0.79, 142711000], 
         ['L1', 'BANAUE', 'IFUGAO', 'Mountainous', '4th', 19120, 22365, 1.17, 142701000], 
         ['L17', 'CITY OF TABUK', 'KALINGA', 'Mountainous', 70025, 103912, 1.48, 143213000] 
         ['L9', 'HINGYON', 'IFUGAO', 'Mountainous', '5th', 6202, 9795, 1.58, 142709000], 
         ['L2', 'HUNGDUAN', ' IFUGAO', 'Mountainous', '4th', 26030, 9933, 0.38, 142702000], 
         ['L3', 'KIANGAN', ' IFUGAO', 'Mountainous', '4th', 20000, 15837, 0.79, 142703000], 
         ['L4', 'LAGAWE', ' IFUGAO ', 'Mountainous', '4th', 20891, 18077, 0.87, 142704000], 
         ['L5', 'LAMUT', ' IFUGAO', 'Mountainous', '4th', 15965, 23088, 1.45, 142705000], 
         ['L13', 'LUBUAGAN', 'KALINGA', 'Mountainous', '4th', 23420, 9369, 0.4, 143206000], 
         ['L6', 'MAYOYAO', 'IFUGAO', 'Mouzntainous', '4th', 23805, 16413, 0.69, 142706000], 
         ['L14', 'PASIL', 'KALINGA', 'Mountainous', '5th', 18900, 9626, 0.51, 143208000], 
         ['L15', 'PINUKPUK', 'KALINGA', 'Mountainous', '1st', 74356, 29596, 0.4, 143209000], 
         ['L16', 'RIZAL', 'KALINGA', 'Mountainous', '4th', 23100, 15942, 0.69, 143211000], 
         ['L18', 'TANUDAN', 'KALINGA', 'Mountainous', '4th', 30755, 8529, 0.28, 143214000], 
         ['L19', 'TINGLAYAN', 'KALINGA', 'Mountainous', '4th', 28300, 12557, 0.44, 143215000], 
         ['L10', 'TINOC', 'IFUGAO', 'Mountainous', '4th', 23970, 14147, 0.59, 142710000] 
        ]; 

        var db = window.sqlitePlugin.openDatabase("weather-app-proper", "1.0", 'Demo', 65536); 

        for (var i = 0; i < preMadeLoc.length; i++) { 
         db.transaction(execLoc(preMadeLoc[i])); 
        } 

        function execLoc(sqls) { 
         return function(tx) { 
          tx.executeSql('insert into locations (id, name, province, topography, classification, land_area, population, population_density, code) values(?, ?, ?, ?, ?, ?, ?, ?, ?)', sqls, function(tx, res) { 
           console.log("rowsAffected: " + res.rowsAffected + " -- should be 1"); 
          }); 
         }; 
        } 
       }).fadeIn(200); 
      }); 

     } 
    }); 
}); 

배열의 첫 번째 인덱스입니다. 아무것도.

어떤 도움이 필요합니까?

답변

0

'tx'데이터가 함수에 전달되지 않는다고 생각합니다. 나는 이런 식으로 뭔가를 시도 할 것입니다 :

db.transaction(function(tx) { 
    for (var i = 0; i < preMadeLoc.length; i++) { 
     tx.executeSql('insert into locations (id, name, province, topography, classification, land_area, population, population_density, code) values(?, ?, ?, ?, ?, ?, ?, ?, ?)', preMadeLoc[i]); 
    } 
}); 

이 다중 SQL 문을 처리 할 수있는 거래 능력을 사용하게하고 tx 변수에 액세스 할 수 있는지 확인합니다 :

   for (var i = 0; i < preMadeLoc.length; i++) { 
        db.transaction(execLoc(preMadeLoc[i])); 
       } 

에이

변경 .