我必须多次选择下拉选项 而且我已经在ajax中获取了结果
$.ajax({
type : 'POST',
data: {id:id},
url : url,
dataType : 'json',
success: function(data){
var len = data.length;
for (var i = 0; i < len; i++) {
var templatename1 = data[i]['templatename'];
var fields = data[i]['fields'];
$('#selectColumn1').val(fields);
}
}
});
在var fields = data[i]['fields'];
中的响应就像a,b,c,d
(逗号分隔)
那么如何在下拉菜单中选择保留的记录复选框,像a,b,c这样选择呢?
答案 0 :(得分:1)
$.ajax({
type : 'POST',
data: {id:id},
url : url,
dataType : 'json',
success: function(data){
var len = data.length;
for (var i = 0; i < len; i++) {
var templatename1 = data[i]['templatename'];
if(data[i]['fields']){
var fields = data[i]['fields'].split(","); // you have to convert comma seperated string into array
}
$('#selectColumn1').val(fields);
$("#selectColumn1").multiselect("refresh"); // To refresh multiselect
}
}
});