JQuery Mobile:如何重新渲染选择框? [英] JQuery Mobile: How to re-render select box?

查看:96
本文介绍了JQuery Mobile:如何重新渲染选择框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一次,当我加载页面时,我的选择框为空:

 < select name =secondaryTitleid = secondaryTitle >< /选择> 

然后我进行ajax调用并获取上述选择框的json数据。

  arrtitle = objSecTitle.getAllSecondaryTitle(serviceId); //它的ajax调用,返回json对象
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];
}
函数removeAllOptions(selectbox){
var i;
for(i = selectbox.options.length-1; i> = 0; i--)
{
selectbox.remove(i);
}
}

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

不要介意!

我应该正确地检查文档:

  //刷新值
$('#select')。selectmenu('refresh');

//刷新并强制重建
$('#secondaryTitle')。selectmenu('refresh',true);


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);

这篇关于JQuery Mobile:如何重新渲染选择框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆