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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4835527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 15:02:13  来源:igfitidea点击:

JQuery Mobile: How to re-render select box?

javascripthtmljquery-mobile

提问by Vikas

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. 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.

我的 ajax 调用是完美的。上面的代码还更改了下拉项。但是当我们使用 jQuery Mobile 时 UI 不会更新,因为它显示/隐藏不同的 div 以供选择弹出窗口。

回答by Vikas

Never mind!

没关系!

I should check documentation properly:

我应该正确检查文档:

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

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

回答by Valdez V.

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