Jquery select2 数据返回后,select2样式没有应用上去
例如:<select class="editSelect_SeverId" id="editSelect_SeverId" name="select_server_address" data-width="150px" onchange="serverIdChange();"></select>AJAX返回值给上面的下拉框后,样式没出现,修复如下:$.ajax({type:
例如:<select class="editSelect_SeverId" id="editSelect_SeverId" name="select_server_address" data-width="150px" onchange="serverIdChange();"></select>
AJAX返回值给上面的下拉框后,样式没出现,修复如下:
$.ajax({
type: 'get',
url: getServerIpListUrl,
dataType: "json",
success: function (data) {
var item = data.serverIpList;
var state = data.result;
if (state == '1') {
for (var i = 0; i < item.length; i++) {
if (i == 0) {
$("#select_severId").append("<option value='" + item[i].serverId + "' selected>" + item[i].serverIp + "</option>");
$("#editSelect_SeverId").append("<option value='" + item[i].serverId + "' selected>" + item[i].serverIp + "</option>");
} else {
$("#select_severId").append("<option value='" + item[i].serverId + "'>" + item[i].serverIp + "</option>");
$("#editSelect_SeverId").append("<option value='" + item[i].serverId + "'>" + item[i].serverIp + "</option>");
}
}
}
$('#editSelect_SeverId').select2({data: item});
}
});
很明显,返回的数据用:$('#editSelect_SeverId').select2({data: item});形式处理下就OK了

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。
更多推荐
所有评论(0)