1. 程式人生 > >ajax非同步請求的list集合,怎麼迴圈新增到select下拉框中?

ajax非同步請求的list集合,怎麼迴圈新增到select下拉框中?

在jsp頁面中,通過非同步請求,返回的list集合,需要迴圈新增到select下拉框中,如下:

$("#fundCode").change(function(){
 var fundCode = $(this).val();
 var financeAcc = $("#financeAcc2").val();
 $.ajax({
url: "${pageContext.request.contextPath}/admin/convert/convertJson",
type: 'GET',
contentType: 'application/json',
data:{fundCode: fundCode,financeAcc:financeAcc},
success: function(result) {
$("#allowtradeVol").val(result.map["allowtradeVol"]);
$("#shortName").val(result.map["shortName"]);
var fundRiskLevel = result.map["riskLevels"];
var riskLevelx = $("#riskLevel2").val();
$("#fundRiskLevel").value = fundRiskLevel;
if(parseInt(fundRiskLevel) != parseInt(riskLevelx)){
$("#aDiv").show();
}
var convertLists = result.convertList;
$.each(convertLists, function (i, item) {
                        jQuery("#targetFundCode").append("<option value="+item.value+">"+item.label+"</option>");
               });
},
});

 });

select下拉框標籤:

<div class="span6 box">
     <label class='control-label'>轉入基金</label>
    <div class='controls'>
    <select class='input-block-level' name="targetFundCode" id='targetFundCode' ">
    </select>
</div>