2011-12-21 3 views
3

私はデータベースからのドロップダウンを設定しようとしています。 jquery/jquery mobileを使用しています。ドロップダウンに値を設定できます。私の問題は、他の要素を選択して最初の要素をもう一度選択しない限り、データが取り込まれると第1の値を表示しないことです。jqueryモバイルを使用したドロップダウンの実装

http://jsfiddle.net/hozefa/TtguK/

上記のフィドルは、私が現在使用していたコードがあります。

+0

:http://jsfiddle.net/TtguK/11/ –

答えて

4

あなたが直面している問題は、あなたが.selectmenu('refresh')を使用して<select>ウィジェットを "リフレッシュ" する必要があるということである。ここでは

var temp = ['5.00', '10.00', '15.00', '25.00', '50.00', '100.00'], 
    output = []; 

//notice I cached the `temp.length` value, the `for` loop will perform faster if this is done 
for(var i = 0, len = temp.length; i < len; i++){ 

    //instead of appending each `<option>` element, it is a better practice to either concoct a string of all the HTML or create an array that will later be turned into a string (here we are pushing new indexes onto an `output` array) 
    output.push('<option value="' + temp[i]+'">' + temp[i] + '</option>'); 
} 

//now make a single `.append()` call with all the HTML in one big string 
//and most importantly, call `.selectmenu("refresh")` after we update the HTML of the select menu so the jQuery Mobile framework will update the widget 
$('#amountsList').append(output.join('')).selectmenu('refresh'); 

はデモです:多分http://jsfiddle.net/TtguK/9/

+0

ありがとう!! – Hozefa

+1

@Hozefaよろしくお願いします。ここから1つの情報だけを取り除いた場合、各jQuery Mobileウィジェットにはこれに類似したものがあり、それらはすべてプログラムで作成/リフレッシュできます。 – Jasper

関連する問題