详细:http://www.cnblogs.com/linJie1930906722/p/6060370.html
$("#name").select2({
language: "zh-CN",
placeholder: "请选择名称",
tags: true,
multiple: false,
allowClear: true,
ajax: {
url: "",
dataType: 'json',
delay: 250,
data: function (params) {
return {
name: params.term //参数
};
},
processResults: function (data, params) {
var array = new Array();
if (data) {
for (var i = 0; i < data.length; i++) {
array.push({ id: data[i].Name, text: data[i].Name });
}
}
var result = new Object();
result.results = array;
return result;
},
cache: true
},
escapeMarkup: function (markup) { return markup; },
minimumInputLength: 2
//templateResult: function (item) {
// return item.text;
//}