我一直在使用Select2版本3进行下拉菜单。但是,我正在尝试升级到最新的v4版本,并且正在努力了解他们的文档。有人能够指出我正确的方向将下面的v3.5代码转换为v4,以便我能理解如何转换我的其余代码吗?
$("#@hp.ID").select2(
{
dropdownAutoWidth: true,
minimumInputLength: 0,
allowClear: getBool("@hp.bAllowClear"),
width: "@hp.Width",
formatResult: formatResults,
formatSelection: formatSelection,
matcher: SetMatcher,
sortResults: SortSelect2,
initSelection: function (element, callback)
{
var id = "@Model"
if ((id != "") && (id != "0") && (id != undefined))
{
$.ajax("@Url.Action("GetVendorsInit", "DropDownManagerAjax")",
{
data: JSON.stringify({ VendorID: id }),
dataType: "json"
}).done(function (data)
{
callback({ id: data.id, text: data.text });
});
}
},
ajax: {
url: "@Url.Action("GetVendors", "DropDownManagerAjax")",
dataType: 'json',
quietMillis: 250,
data: function (term, page)
{
return {
q: term,
iDisplayStart: (page - 1) * 100,
iDisplayLength: 100,
sEcho: 0,
iSortCol_0: 0,
sSortDir_0: 'asc',
};
},
results: function (data, page)
{
var more = (page * 30) <= data.total;
return { results: data.data, more: more };
},
cache: true
},
dropdownCssClass: "autoWidth",
escapeMarkup: function (m) { return m; },
placeholder: 'Select Vendor...'
});