Problem in fetching data from SQLite database and displaying it as list
Hello!
I am new to jQuery Mobile. I am trying to fill a list with "li" items by fetching records from SQLite database. The problem that I am facing is that all items are displayed as a single "li". Below image shows what I am getting
And I should be getting is
The code that I have written is
- var strItems = "";
-
- var query = "SELECT id, name FROM categories WHERE ID IN (1, 2, 3)";
- try
- {
- initDB();
- //fillCategories();
- localDB.transaction(function(transaction){
- transaction.executeSql(query, [], function(transaction, results){
- for (var i = 0; i < results.rows.length; i++) {
- var row = results.rows.item(i);
- var categoryId = row['id'];
- var categoryName = row['name'];
-
- if(i == 0)
- strItems = "<li data-theme=c><a href=#page1?id=" + categoryId + " data-transition=slide>" + categoryName + "</a></li>";
- else
- strItems += "<li data-theme=c><a href=#page1?id=" + categoryId + " data-transition=slide>" + categoryName + "</a></li>";
- }
- $("ul").html(strItems);
- }, null);
- });
- }
- catch (e) {
- document.write("Error: Unable to select data from the db " + e + ".");
- }
Please tell me where am I making a mistake.