之前用本地下拉框数据 搜索框正常使用 ajax就不行了
js代码
/* 执行select2方法初始化 */
function select2Execute() {
$(function() {
/*1-本地注入方式*/
/* $(".downList2").select2({
// $("select[name='xuewei_id']").select2({
// $('select[id="xuewei_id"]').select2({
// $('#xuewei_id').select2({
// $("#selectSection").find("select.combox").select2({
// $(".select2-selection__choice").select2();
// $(".combox").select2({
placeholder : "请至少选择一个人名",
tags : true,
createTag : function(decorated, params) {
return null;
},
width : '256px',
});*/
//2- AJAX获取数据方式
$(".downList2").select2({
ajax: {
url: 'http://localhost:8080/erzhentang/manage/forAjax.do?requestType=12.5_1',
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term,
};
},
processResults: function (data) {
return {
results: data
};
},
cache: true
},
escapeMarkup: function (markup) { return markup; }, // 自定义格式化防止xss注入
minimumInputLength: 0,
formatResult: function formatRepo(repo){return repo.text;}, // 函数用来渲染结果
formatSelection: function formatRepoSelection(repo){return repo.text;} // 函数用于呈现当前的选择
});
select标签 拼接在js里了
var str = "";
str +="<select name=\"xuewei_id\" class=\"form-control input-sm downList2\" multiple>";
str +="<option></option>";
"</select>";