好的我正在尝试用JSON响应来填充组合框,就像这样......
[{"uid":"95bf721c-8c24-432e-83e4-7233169f23fa","name":"MARKETING I MARKETING MENAD\u017dMENT","selected":false},{"uid":"ed4293ff-9c89-4052-9fec-852d34c6150d","name":"PRODAJA I MENAD\u017dMENT PRODAJE","selected":false}]
数字应该是值,Text是文本,而对于第3个参数,我有false / true选项。如果为true,则应在下拉菜单中选择attr。
我在想创建标签 标签
并使用j查询添加选项,带有一些循环。也许有人知道如何做到这一点
答案 0 :(得分:1)
var arr = [{"uid":"95bf721c-8c24-432e-83e4-7233169f23fa","name":"MARKETING I MARKETING MENAD\u017dMENT","selected":false},{"uid":"ed4293ff-9c89-4052-9fec-852d34c6150d","name":"PRODAJA I MENAD\u017dMENT PRODAJE","selected":true}];
var sel = $('<select/>');
for (var i = 0;i<arr.length;i++) {
var obj = arr[i];
var opt = $('<option/>');
opt.val(obj.uid).text(obj.name)[0].selected = obj.selected;
sel.append(opt);
}
答案 1 :(得分:0)
var tiposItems = "<option value='" + valueSelectOne + "'>" + textSelectOne + "
$.each(JSONdata, function (i, tipo) {
tiposItems += "<option value='" + tipo.Value + "'>" + tipo.Text + "</option>";
});
$('#yourDDL').html(tiposItems);
&#13;