しばらくの間、ドロップダウンに 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...'
});