2
我想通過讀取JSON變量動態創建組合框。嵌套的jQuery每個語句在第一個完成之後運行
問題是第一個$.each()
語句總是在第二個$.each()
語句之前完成。
這使得兩個選項不在<select>
元素之外。
我在做什麼錯?
var oFields = {
"fields": [
{"name": "idtipopratica", "label": "ID Tipo Prat.", "type": "hidden", "visible": "true", "disabled": "false"},
{"name": "tipologia", "label": "Tipologia", "type": "select", "selectParams": {
"source": "list",
"values": {"CC":"Conto Corrente","FI":"Conto Finanziario"}
},"visible": "true", "disabled": "false"}
]
};
var html = '<form id="editForm" method="post" class="form-horizontal">';
$.each(oFields.fields, function (i, object) {
switch(object.type) {
case "select":
html += '<select id="' + object.name + '" name="' + object.name + '"/>';
var selectParams = object.selectParams;
console.log(selectParams);
if (selectParams.source === "table") {
//console.log(selectParams.keycolumn);
} else {
$.each(selectParams.values, function(k,v){
html += '<option value="' + k + '">' + v + '</option>';
console.log(k+"|"+v);
});
}
break;
default:
html += '<input type="' + object.type + '" id="' + object.name + '" name="' + object.name + '"/>';
}
html += '</select>';
});
html += '</form>';
$("body").html(html);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>