简体   繁体   中英

JQuery Mobile: How to re-render select box?

First time, When I load page, my select box is empty:

<select name="secondaryTitle" id="secondaryTitle"></select>

Then I make ajax call and get the json data for above select box.

arrtitle = objSecTitle.getAllSecondaryTitle(serviceId); // its an ajax call, that returns json object
var obj = jQuery("#secondaryTitle");
removeAllOptions(obj);
for(i=0;i<arrtitle.length;i++)
{
    obj.options.length=obj.options.length + 1;
    obj.options[obj.options.length - 1].text = arrtitle[i][1];
    obj.options[obj.options.length - 1].value = arrtitle[i][0];
}
function removeAllOptions(selectbox){
    var i;
    for(i=selectbox.options.length-1;i>=0;i--)
    {
        selectbox.remove(i);
    }
}

My ajax call is perfect. Above code also changes the drop-down items. But UI will not be updated when we use jQuery Mobile, as it show/hide different div for selection popup.

Never mind!

I should check documentation properly:

//refresh value         
$('#select').selectmenu('refresh');

//refresh and force rebuild
$('#secondaryTitle').selectmenu('refresh', true);

Don't ask me why, but this only worked for me until I used double quotes ->"<- for all strings involved in this instruction:

$("#secondaryTitle").selectmenu("refresh", true);//working

I had it like this:

$('#secondaryTitle').selectmenu('refresh', true);//not working

and it not worked :S :S :S

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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