Select2 JS バージョン 4.0.0-rc.1 を使用していますが、リモート Ajax メソッドで提案を読み込むのに問題があります。
以下はマークアップとコードです
<select class="form-control input-sm" id="selFrame1" name="selFrame1">
<option> Select Frame </option>
</select>
JavaScript Jquery
$('#selFrame1').select2({
ajax: {
url: siteUrl+"suggest/frames",
dataType: 'json',
delay: 250,
method:'POST',
data: function (params) {
return {
q: params.term, // search term
page: params.page
};
},
processResults: function (data, page) {
// parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to
// alter the remote JSON data
return {
results: data.result
};
},
cache: true
}
});
サーバーから返された Json Result
{results: [{"Code":"123360000"},{"Code":"123360358"},{"Code":"123364000"},{"Code":"123400000"}], more: false }
提案を表示するために特定の関数を記述する必要があるかどうかはまったくわかりません。Ajax セクションのコメントには、結果の Json データを変更すべきではないと書かれています。
ここで、提案を表示するためにコードを機能させるには、さらに何をすべきか教えてください。
select2の新しいバージョンでは、多くのものが変更されたと思います。