Select2 下拉列表 updating/highlighting 不正确
Select2 dropdown list not updating/highlighting correctly
当我在搜索字段中输入任何内容时,它总是只显示初始列表(见屏幕截图)。
我有一个下拉列表:
<asp:Dropdownlist ID="animals" name="animals" runat="server" />
它正在像这样填充:
$(document).ready(function () {
$("#animals").select2({
placeholder: '-- None Selected --',
allowClear: true,
ajax: {
url: function () {return "json/animals.aspx";},
dataType: "JSON",
processResults:function(data){return {results: data};},
error: function (jqXHR, exception) {
console.log(jqXHR.responseText)
}
}
});
}
ajax 正确获取列表,如屏幕截图所示,但当我输入“1”时,它根本不匹配,只显示整个列表。如果我向任何键发送垃圾邮件,那么它会出错并在 jqXHR.responseText
中给出未定义。我在这里做错了什么吗?这是我的包括:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
试试这个:
jQuery.getJSON('json/animals.aspx')
.done( function( data ) {
data = $.map(data, function(item) {
// replace item. id and text with your animal json properties.
return { id: item.id, text: item.name};
});
jQuery('#animals').select2({
placeholder: 'Type any ....',
allowClear: true,
minimumInputLength: 0,
multiple: true,
data: data
});
}
);
当我在搜索字段中输入任何内容时,它总是只显示初始列表(见屏幕截图)。
我有一个下拉列表:
<asp:Dropdownlist ID="animals" name="animals" runat="server" />
它正在像这样填充:
$(document).ready(function () {
$("#animals").select2({
placeholder: '-- None Selected --',
allowClear: true,
ajax: {
url: function () {return "json/animals.aspx";},
dataType: "JSON",
processResults:function(data){return {results: data};},
error: function (jqXHR, exception) {
console.log(jqXHR.responseText)
}
}
});
}
ajax 正确获取列表,如屏幕截图所示,但当我输入“1”时,它根本不匹配,只显示整个列表。如果我向任何键发送垃圾邮件,那么它会出错并在 jqXHR.responseText
中给出未定义。我在这里做错了什么吗?这是我的包括:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
试试这个:
jQuery.getJSON('json/animals.aspx')
.done( function( data ) {
data = $.map(data, function(item) {
// replace item. id and text with your animal json properties.
return { id: item.id, text: item.name};
});
jQuery('#animals').select2({
placeholder: 'Type any ....',
allowClear: true,
minimumInputLength: 0,
multiple: true,
data: data
});
}
);