如何从数据库中检索值并使用(jqtouch + phonegap)在html5中显示它

我正在尝试使用html5,javascript,jqtouch和phonegap为移动健康制作Iphone应用程序。 我这样做是为了学习使用html5 jqtouch和phonegap构建iPhone应用程序的学校项目。

我能够使用pName作为数据库表中的列创建一个数据库。 但我无法在index.html中的空div(名为patientList的第一个pannel)中填充整个患者姓名列表。

我创建了一个名为index.html的文件。 此文件具有不同的面板。 第一个pannel是一个patientList面板。 第二个pannel是在数据库中创建一个新条目。 在数据库中创建新条目后,第一个名为患者列表的面板应填充患者的所有姓名。 我的代码成功创建了一个数据库,但它没有在PatientList面板中显示患者的任何名称(pName)。

我是第一次使用HTML5,CSS,JAVASCRIPT,JQTOUCH和PHONEGAP制作iphone应用程序。 我需要你的帮助。

我的index.html看起来像这样

patientList

+
  • Label
  
Cancel

New Patient

Save

+

我的iphone.js看起来像这样

  var jQT = new $.jQTouch({ }); var db; $(document).ready(function(){ $('#newEntry form').submit(createEntry); $('#patientList li a').click(function(){ var nameOffset = this.id; sessionStorage.currentName = nameOffset; // storing the clicked patient name refreshEntries(); }); // creating a database with name PatientDataBase and which has the table named patientRecord1 var shortName = 'patientDataBase'; var version = '1.0'; var displayName = 'patientDataBase'; var maxSize = 65536; db = openDatabase(shortName, version, displayName, maxSize); db.transaction( function(transaction) { transaction.executeSql( 'CREATE TABLE IF NOT EXISTS patientRecord1 ' + ' (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, ' + ' pName TEXT NOT NULL);' ); } ); }); // Function created a new enty in the database table patientRecord1 function createEntry() { var pName = $('#PatientName').val(); db.transaction( function(transaction) { transaction.executeSql( 'INSERT INTO patientRecord1 (pName) VALUES (?);', [pName], function(){ refreshEntries(); jQT.goBack(); }, errorHandler ); } ); return false; } // this function is used to retrive the data from the table and populate in the html pannel named patientList function refreshEntries() { $('#patientList ul li:gt(0)').remove(); db.transaction( function(transaction) { transaction.executeSql( 'SELECT * FROM patientRecord1;', function (transaction, result) { for (var i=0; i < result.rows.length; i++) { var row = result.rows.item(i); var newEntryRow = $('#entryTemplate').clone(); newEntryRow.removeAttr('id'); newEntryRow.removeAttr('style'); newEntryRow.data('entryId', row.id); newEntryRow.appendTo('#patientList ul'); newEntryRow.find('.label').text(row.pName); } }, errorHandler ); } ); } function errorHandler(transaction, error) { alert('Oops. Error was '+error.message+' (Code '+error.code+')'); return true; } 

请告诉我我做错了什么。

用以下内容替换refreshEntries()函数:

 function refreshEntries() { $('#patientList ul li:gt(0)').remove(); db.transaction( function(transaction) { transaction.executeSql('SELECT * FROM patientRecord1;', [], function(transaction, result) { for (var i = 0; i < result.rows.length; i++) { var row = result.rows.item(i); var newEntryRow = $('#entryTemplate').clone(); newEntryRow.removeAttr('id'); newEntryRow.removeAttr('style'); newEntryRow.data('entryId', row.id); newEntryRow.appendTo('#patientList ul'); newEntryRow.find('.label').text(row.pName); } }, errorHandler); }); } 

你在executeSql参数中错过了一个param数组。 我把新代码放在这里