如何从数据库中检索值并使用(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看起来像这样
- Label
我的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数组。 我把新代码放在这里
- PhoneGap 1.5.0 Android Cordova AJAX JSON
- 在Jquery Mobile或PhoneGap中禁用自动旋转
- Phonegap:构建转换后,透视CSS属性不起作用?
- Phonegap Windows Phone 7使用jQuery动态HTML加载和跨域调用
- 上传多张图片时出现问题 – phonegap
- 如何从json为100个项目创建html而不创建100个单个html文件?
- 如何使用javascript或Jquery更改屏幕方向?
- 用于WP8(Lumia 920)设备的jQuery / HTML5 / gwt应用程序:垂直css滚动修复
- 第一次通话时,Phonegap / jquery移动幻灯片转换无法正常工作