简体   繁体   English

无法使用jQuery填充选择下拉列表

[英]unable to populate a select dropdown list using jquery

I am using websql to store some data for a web app. 我正在使用websql来存储Web应用程序的一些数据。 Now I am trying to retrieve it and populate it into a select dropdown box. 现在,我正在尝试检索它并将其填充到选择下拉框中。 I used the html function to set the values. 我使用html函数设置值。 But for some reason, the select dropdown box does not get populated. 但是由于某种原因,没有填充选择下拉框。

HTML file HTML文件

HTML File HTML文件

Here is the Javascript file 这是Javascript文件


var dbConnection=null;
var dbName='ExpensesAppDb';
var dbVersion='1.0';
var dbDisplayName='Expenses Application Database';
var dbSize=1024*1024*5;
var categoryTable="categories";
var name="name";
var _id="id";
var categoryTableQuery="create table "+categoryTable+"("+_id+" integer primary key,"
+ name +" text)";
var options="";

$(function()
{
dbConnection=openDatabase(dbName,dbVersion,dbDisplayName,dbSize);
createCategoryTable();
init();
fetchCategories();
});

createCategoryTable=function()
{
dbConnection.transaction(function(tx){
 tx.executeSql(categoryTableQuery,[],
 function(){alert('Category Table created');},
 function(tx,error){ alert(error.message);});
});
};

insertCategory=function(aName)
{
dbConnection.transaction(function(tx){
    tx.executeSql("insert into "+categoryTable+"("+name
    +") values(?)",[aName],
    function(tx,result)
    {

    },
    function()
    {

    }
)
    });
        };


fetchCategories=function()
{
dbConnection.transaction(function(tx){
    tx.executeSql("SELECT "+_id+","+name +" FROM "+categoryTable, [],
    function(SQLTransaction, data){
    for (var i = 0; i "+aName+""
}

function populateCategoryList()
{
 $('#expensesCategory').html(options);
 $("#expensesName").val("Hello");
}

function init()
{
    insertCategory("Food");
    insertCategory("Rent");
    insertCategory("Gas");
    insertCategory("Entertainment");
}

PS: How does one show the source of the HTML File over here. PS:如何在此处显示HTML文件的来源。 I guess the engine was parsing the html file. 我猜引擎正在解析html文件。

I figured it out. 我想到了。 I had to refresh the display state of the selection box by using $("#expensesCategory").selectmenu('refresh', true); 我必须使用$(“#expensesCategory”)。selectmenu('refresh',true);刷新选择框的显示状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM