jQuery Mobile选定的选项未在“刷新"时更新 [英] jquery mobile selected option not updating on 'refresh'

查看:158
本文介绍了jQuery Mobile选定的选项未在“刷新"时更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQueryMobile,当我更改选择小部件的内容然后在其上调用刷新"时,所选选项的文本不会更改.这是场景...

Using jQueryMobile, when I change the contents of a select widget and then call 'refresh' on it, the text of the selected option is not changed. Here's the scenario...

选择"小部件已经存在于页面div中.当用户转到该屏幕时,将根据他们选择的进入该页面的按钮来动态创建选项.该选项列表是根据

The 'select' widget exists in the page div already. When the user goes to that screen, the options are dynamically created based on the button they selected to go to that page. This option list is built and added as per

$('#searchReasonList').append(optionList)

第一次进入新页面效果很好.当他们离开并返回时,我执行

The first time into the new page all works well. When they navigate away and come back in, I do

$('#searchReasonList').empty()

然后建立正确的选项列表并执行相同的追加并调用:

Then I build the correct option list and do the same append and call:

$('#searchReasonList').selectmenu('refresh',true)

本机选择确实刷新了,我可以从选项中进行选择.但是,所选选项不会显示.仅占位符.

The native select is indeed refreshed, and I am able to choose from the options. However, the selected option doesn't show up. Only the placeholder is seen.

显示增强的标记:

<div class="ui-select">
  <div class="ui-btn ui-btn-icon-right ui-btn-corner-all ui-shadow ui-btn-up-c" data-theme="c">
    <span class="ui-btn-inner ui-btn-corner-all">
      <span class="ui-btn-text">Select Reason</span>
      <span class="ui-icon ui-icon-arrow-d ui-icon-shadow"></span>
    </span>

    <select id="searchReasonList" name="searchReasonList" data-placeholder="true">
      <option value="">Select Reason</option>
      <option value="1">Option 1</option>
      <option value="2">Option 2</option>
    </select>
  </div>
</div>

具有class='ui-btn-text'的span标签未使用所选选项的标签进行更新.它只是保留搜索原因",这是我的占位符的标签.

It's that span tag with class='ui-btn-text' that is not being updated with the selected option's label. It just stays "Search Reason", which is the label of my placeholder.

还有其他要做的事情吗?

Is there something else that needs to be done?

推荐答案

使用jQuery 1.0.1(当前最新的稳定版本),您可以使用.selectmenu('refresh')刷新select-widget.

Using jQuery 1.0.1 (latest stable version at this time) you can use .selectmenu('refresh') to refresh a select-widget.

$('select').empty().append('<option value="foo">Bar</option>').selectmenu('refresh');

这是一个演示: http://jsfiddle.net/4Thzt/

使用$('select').selectmenu('refresh', true);(请注意, true)时,您不仅要强制刷新小部件,还要重新构建小部件,这将始终显示占位符文本. 来源: http://jquerymobile. com/demos/1.1.0-rc.1/docs/forms/selects/methods.html

When you use $('select').selectmenu('refresh', true); (notice the , true), you are forcing the widget to not only be refreshed, but rebuilt, which will always show the placeholder text. Source: http://jquerymobile.com/demos/1.1.0-rc.1/docs/forms/selects/methods.html

这篇关于jQuery Mobile选定的选项未在“刷新"时更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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