简体   繁体   English

JQuery Mobile:如何重新渲染选择框?

[英]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. 然后我进行ajax调用并获取上面选择框的json数据。

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. 我的ajax电话很完美。 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. 但是当我们使用jQuery Mobile时,UI不会更新,因为它显示/隐藏选择弹出窗口的不同div。

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 $(“#secondaryTitle”)。selectmenu(“refresh”,true); //工作

I had it like this: 我这样做了:

$('#secondaryTitle').selectmenu('refresh', true);//not working $('#secondaryTitle')。selectmenu('refresh',true); //不工作

and it not worked :S :S :S 它不起作用:S:S:S

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

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