出力されるマークアップのサイズを削減するために、JQueryを使用してSELECT要素にデータを入力しています。
1つを除いて、すべてが私が望むように機能しています。並べ替え。
以下のコードに到達するまでに.each
、JQueryはval
値ではなく値でソートしているようtext
です。text
変数でリストを生成する順序で、値またはより理想的にはリストをソートする必要がありますdyn_list_product
。
どうすればこれを達成できますか?
どうもありがとう。
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Sample Code</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type = "text/javascript" >
$(document).ready(function(){
var dyn_list_product = { 10075:'abc', 10635:'def', 10246:'ghi', 10245:'jkl', 10076:'mno', 10642:'pqr', 10995:'stu', 10255:'vwx', 10230:'yz' };
$('.jquery_list_product').append( $('<option></option>').val('').html('----------') );
$.each( dyn_list_product , function(val, text) { $('.jquery_list_product').append( $('<option></option>').val(val).html(text) ); });
})
</script>
</head>
<body>
<select name="insert-1[]" class="jquery_list_product"></select>
<select name="insert-2[]" class="jquery_list_product"></select>
<select name="insert-3[]" class="jquery_list_product"></select>
</body>
</html>