2012-10-26 84 views
0

我正在與phonegap opendatabase和一切工作正常在我的桌面上的Chrome瀏覽器,但是當我在我的android設備上運行它,然後單擊按鈕調用insertRecord()它說不與日食,我得到錯誤Phonegap沒有拿起交易功能

10-26 10:37:13.191: E/Web Console(12134): Uncaught ReferenceError: insertRecord is not defined at file:///android_asset/www/index.html:137 

我的代碼看起來象

document.addEventListener("deviceready", onDeviceReady, false); 

// PhoneGap is ready 
// 
function onDeviceReady() { 


var minChange; 
var pumpBore; 
var sInches; 
var sMin; 
var maxEfficiency; 
var field; 
var percent; 
var calcSlide; 
var results; 
var id; 
var listing; 
var slider_value; 
var getMin; 

var dateDay = "Wed"; 
var dateNum = "22"; 
var date = new Date(); 
var dateDay = date.getDay(); 
var dateNum = date.getDate(); 
var hour = date.getHours(); 
var min = date.getMinutes(); 
var dateTime = hour + ":" + min; 

pumpBore = $("#pumpBore").val(); 
sInches = $("#sInches").val(); 
sMin = $("#sMin").val(); 
calcSlide = $("#calcSlide").val(); 
field = $('#field').val(); 
results = $('#results'); 
id = $('#id'); 
getMin = $('#slider-1').val(); 

// FUNCTION TO CALCULATE AND DISPLAY PRODUCTION 
function calculate(sMin) { 
    if (sMin == null) 
     sMin = sMin 

    pumpBore = $("#pumpBore").val(); 
    sInches = $("#sInches").val(); 
    calcSlide = $("#calcSlide").val(); 
    field = $('#field').val(); 

    console.log("Calc pump Bore: " + pumpBore); 
    console.log("Calc Inches: " + sInches); 
    console.log("Calc Min: " + sMin); 
    console.log("Field Amount: " + field); 
    console.log("Percentage: " + percent); 
    console.log('Time: ' + dateTime); 
    maxEfficiency = Math.round(parseFloat(pumpBore) * parseFloat(sInches) 
      * parseFloat(sMin)); 

    console.log("Max Efficiency " + maxEfficiency); 
    // console.log(calcSlide); 
    $("#sMin").val(sMin); 
    $("#barrels").val(maxEfficiency); 

    percent = Math.round(parseFloat(field)/parseFloat(maxEfficiency) * 100); 

    $('#percent').val(percent + "%"); 

    console.log("========================================"); 
    sMin = $('#sMin').val(); 
} // eof calculate 

function consoleList() { 
    console.log('============================'); 
    console.log("pump Bore: " + pumpBore); 
    console.log("Stroke Inches: " + sInches); 
    console.log("Strokes Per Minute: " + $('#sMin').val()); 
    console.log("Max Efficiancy: " + maxEfficiency); 
    console.log("Field: " + field); 
    console.log("Field %: " + percent); 
    console.log('Time: ' + dateTime); 
    console.log('Slider Value: ' + slider_value); 
    console.log('============================'); 
    console.log(results); 

} 

var strokeMin = $('#sMin').val(); 
var createStatement = "CREATE TABLE IF NOT EXISTS Notes (id INTEGER PRIMARY KEY AUTOINCREMENT, dateDay TEXT, dateNum TEXT, dateTime TEXT, pumpBore TEXT, sInches TEXT, sMin TEXT, maxEfficiency TEXT, field TEXT, prodPercent TEXT)"; 
var selectAllStatement = "SELECT * FROM Notes ORDER BY id DESC"; 
var insertStatement = "INSERT INTO Notes (dateDay, dateNum, dateTime, pumpBore, sInches, sMin, maxEfficiency, field, prodPercent) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; 
var deleteStatement = "DELETE FROM Notes WHERE id=?"; 
var dropStatement = "DROP TABLE Notes"; 
var insertValues = "[pumpBore.value, sInches.value, sMin.value, maxEfficiency.value, field.value, percent.value]"; 
var testInsertValues = '["123", "234", "567", "657", "753", "2654"]'; 

var db = openDatabase("noteList", "1.0", "Note List", 500000); 
var dataset; 
createTable(); 

function onError(tx, error) { 
    alert(error.message); 
} 

function showRecords() { 
    results.html(''); 
    db.transaction(function(tx) { 
     tx.executeSql(selectAllStatement, [], function(tx, result) { 
      dataset = result.rows; 
      for (var i = 0, item = null; i < dataset.length; i++) { 
       item = dataset.item(i); 

       listing = '<div class="noteContainer">' 
         + '<div class="dateContainer">' 
         + '<span id="weekDay" class="">' 
         + item['dateDay'] 
         + '</span>' 
         + '<span id="date" class="">' 
         + item['dateNum'] 
         + '</span>' 
         + '<span id="time" class="">' 
         + item['dateTime'] 
         + '</span>' 
         + '</div><!-- eof dateContainer -->' 
         + '<div class="specContainer">' 
         + '<span class="">pump Bore: ' 
         + item['pumpBore'] 
         + '</span>' 
         + '<span class="">Stroke Length: ' 
         + item['sInches'] 
         + '</span>' 
         + '<span class="">Stroke/Min: ' 
         + item['sMin'] 
         + '</span>' 
         + '<span class="">Barrels: ' 
         + item['maxEfficiency'] 
         + '</span>' 
         + '<span class="">Field Prod: ' 
         + item['field'] 
         + '</span>' 
         + '<span class="">Production %: ' 
         + item['prodPercent'] 
         + '</span>' 
         + '</div><!-- eof specContainer -->' 
         + '<div class="mailButton">' 
         + '<img src="images/mail_Button.png" alt="mail" />' 
         + '</div><!-- eof mail -->' 
         + '<div id="" style="clear:both"></div>' 
         + '<a href="#" onclick="deleteRecord(' 
         + item['id'] 
         + ')">delete</a></li>'; 
       +'</div><!-- eof noteContainer -->'; 
       console.log(i); 
       results.append(listing); 
      } 
     }); 
    }); 
} 

function createTable() { 
    db.transaction(function(tx) { 
     tx.executeSql(createStatement, [], showRecords, onError); 
    }); 
} 

function insertRecord() { 
    db.transaction(function(tx) { 
     // consoleList(); 
     console.log("The field:" + field); 
     tx.executeSql(insertStatement, [ dateDay, dateNum, dateTime, pumpBore, sInches, getMin, 
       maxEfficiency, field, percent ], loadAndReset, onError); 
     // ("Row Inserted!"); 
    }); 
} 

function loadRecord(i) { 
    var item = dataset.item(i); 
    dateDay.value = item['dateDay']; 
    dateNum.value = item['dateNum']; 
    dateTime.value = item['dateTime']; 
    pumpBore.value = item['pumpBore']; 
    sInches.value = item['sInches']; 
    sMin.value = item['sMin']; 
    maxEfficiency.value = item['maxEfficiency']; 
    field.value = item['field']; 
    percent.value = item['prodPercent']; 
    id.value = item['id']; 
} 

function updateRecord() { 
    db.transaction(function(tx) { 
     tx.executeSql(updateStatement, [ dateDay.value, dateNum.value, 
       dateTime.value, pumpBore.value, sInches.value, sMin.value, 
       maxEfficiency.value, field.value, percent.value ], 
       loadAndReset, onError); 
    }); 
} 

function deleteRecord(id) { 
    db.transaction(function(tx) { 
     tx.executeSql(deleteStatement, [ id ], showRecords, onError); 
    }); 
    resetForm(); 
} 

function dropTable() { 
    db.transaction(function(tx) { 
     tx.executeSql(dropStatement, [], showRecords, onError); 
    }); 
    resetForm(); 
} 

function loadAndReset() { 
    // alert(listing); 
    resetForm(); 
    showRecords(); 
} 

function resetForm() { 
    dateDay.value = ''; 
    dateNum.value = ''; 
    dateTime.value = ''; 
    pumpBore.value = ''; 
    sInches.value = ''; 
    sMin.value = ''; 
    field.value = ''; 
    percent.value = ''; 
    id.value = ''; 
} 

$(function() { 
    $('#slider-1').live('change', function(){ 
     slider_value = $(this).val() 
     console.log(slider_value) 
     minChange = slider_value; 
     // minChange = 100 - minChange; 
     minChange = Math.round(minChange); 
     console.log("Min Change " + minChange); 

     calculate(minChange); 
     // do whatever you want with that value... 
    }) 
}); 

///Knob Turn Function 
$(function() { 

    $('#dialBG, #dialBG2 ').knobKnob({ 
     snap : 1, 
     value : -10, 
     turn : function(ratio) { 
      console.log(ratio); 
      //minChange = (ratio * 100); 
      // minChange = 100 - minChange; 
      //minChange = Math.round(minChange); 
      //console.log("Min Change " + minChange); 

      //calculate(minChange); 
     } 
    }); 

}); 

} 

我有一個鏈接到它作爲kzoomarketing.com/apps/oilapp/121/因此可以看出。在計算器頁面右上角的保存按鈕記錄所有字段並將它們填充到筆記頁面中。它在Web瀏覽器中工作正常。

如果我改變js函數被包裝在ondeviceready並運行它,我得到上面提到的日誌貓錯誤。

任何人都可以幫助我得到這個android設備上運行。

+0

「index.html」的第137行是什麼? –

+0

回答

1

insertRecord函數在onDeviceReady函數中定義。

您必須重新組織代碼,以便像這樣的事件處理程序可以全局訪問(即從HTML)。