Jquery-Mobile: Append the data to the non-native select option menu

news/2024/7/11 0:43:35 标签: jquery, select

select_option_menu_0">Jquery-Mobile: Append the data to the non-native select option menu

原文

Question

I have a problem with adding the data to non-native select option menu on Jquery Mobile. Here’s my code :

in html :

<select id="my-select" data-native-menu="false"></select>

in javascript :

var len = results.rows.length;
var s = '';
for (var i=0; i<len; i++){
$('#my-select')
.html($("<option></option>")
.attr("value",results.rows.item(i).id)
.text(results.rows.item(i).name));
}

So, if i delete the “data-native-menu=“false””, that code is works perfectly. Whats wrong with my code ?

Answer

You need to tell jQM to refresh/rebuild the widget any time you change the options within the selectmenu:

http://api.jquerymobile.com/selectmenu/#method-refresh

$('#my-select').selectmenu( "refresh", true );

FYI. by using html($("")…) within the for loop, you are overwriting the all options each time. Instead, use .empty() to clear existing options before the loop, and use append() to add the new ones.

To make it more efficient, create a string of all options and append them to the DOM once after the loop:

var opts = '';
for (var i=0; i<len; i++){
    opts += '<option value="' + results.rows.item(i).id + '">' + results.rows.item(i).name + '</option>';
}
$('#my-select').empty().append(opts).selectmenu( "refresh", true );

http://www.niftyadmin.cn/n/1108092.html

相关文章

c语言中的goto语句

goto 语句标号;实现无条件跳转限制:goto和语句标号必须在同一个函数中&#xff0c;可以不在同一个循环层中.#include <stdio.h> int main(void){int i,sum0;i1; loop:if(i<100){sumi;i;goto loop;}printf("sum%d\n",sum);return 0; } 结果为5050转载于:http…

Linux开发者掀起自由软件界轩然大波(转)

Linux开发者掀起自由软件界轩然大波(转)[more]  作者&#xff1a;xiaguang 来源&#xff1a;CSDN一周之前&#xff0c;几位 Linux kernel 开发者在 LKML上的一篇长文在自由软件世界里掀起了轩然大波。 RMS 让人感觉是一个比较激进的理想主义者和实干家&#xff08;注意&…

CentOS 7 安装MySQL5.7.25

STEP 1. 下载 去往官方下载MySQL包.http://dev.mysql.com mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz [rootstudy mysql] pwd /root/mysql [rootstudy mysql] wget https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-i686.tar.gz STEP 2. 解压缩 [roo…

一个嵌入式Linux系统的键盘驱动实现(转)

一个嵌入式Linux系统的键盘驱动实现(转)[more]  1 引言 Linux由于其具有内核强大且稳定&#xff0c;易于扩展和裁减&#xff0c;丰富的硬件支持等诸多优点&#xff0c;在嵌入式系统中得到了广泛的应用。很多嵌入式Linux系统&#xff0c;特别是一些具有与用户强交互的嵌入式系…

基于spring注解AOP的异常处理

一、前言 项目刚刚开发的时候&#xff0c;并没有做好充足的准备。开发到一定程度的时候才会想到还有一些问题没有解决。就比如今天我要说的一个问题&#xff1a;异常的处理。写程序的时候一般都会通过try...catch...finally对异常进行处理&#xff0c;但是我们真的能在写程序的…

腾讯云CVM服务器怎么建网站

腾讯云云服务器CVM站在用户的角度看就相当于一台计算机&#xff0c;虽然实际上它是一个虚拟服务器&#xff0c;是一个大的云端服务器集群虚拟出来的一个虚拟服务器&#xff0c;在使用上直接当做一个实际的服务器即可。那么&#xff0c;对于一个新手菜鸟来说&#xff0c;如何使用…

关于OpenOCD+ST-LINK的若干问题

关于OpenOCDST-LINK的若干问题 http://blog.csdn.net/zoomdy/article/details/52884854 mingdu.zheng at gmail dot com 没有访问权限 当前用户对USB设备没有访问权限的话&#xff0c;OpenOCD会返回如下错误提示&#xff1a; Error: libusb_open() failed with LIBUSB_ERRO…

详解Linux操作系统的内核空间保护(转)

详解Linux操作系统的内核空间保护(转)[more]  看了LINUX代码,感觉其对内核内存的保护做得不是很好,还有感觉大家有些地方理解不对(主要是LINUX的代码看起来的样子和实际的样子不太一样),所以谈谈我对LINUX系统内核空间的保护和用户空间与系统空间数据传递的代码看法。注意我说…