select2 ajax加载数据,支持模糊查询(非本地)

$('#select_yx').select2({
placeholder: "----请选择院系----",
width: "183px",
allowClear: true,
language: {
noResults: function (params) { return "暂无数据"; }
},
minimumResultsForSearch: -1,
ajax: {
url: apiaddress + '/Institute/GetInstitutes',
dataType: 'json',
method: 'POST',
delay: 500,
data: function (params) {
var query = {
Name: params.term
};
return query;
},
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Bearer " + vToken);
},
processResults: function (data, params) {
var results = [];
if (data != null) {
var tmp = data.result;
for (var i in tmp) {
var temp = tmp[i];
results.push({ id: temp.id, text: temp.name });
}
}
return {
results: results
};
}
}
});

转载于:https://www.cnblogs.com/Anthony518/p/11258499.html

你可能感兴趣的:(select2 ajax加载数据,支持模糊查询(非本地))