私は select2 の最新バージョン (バージョン 4) を使用しています。AJAX 経由でリクエストを行うことができ、応答が正常であることを既に確認しています。ただし、選択は、検索で見つかった結果をオプションに入力していません。おそらく何か不足していますが、わかりません。コードは次のとおりです。
<script type="text/javascript">
$("#cliente").select2({
//allowClear: true,
ajax: {
url: "<%= clientes_getclientes_path(format: 'json') %>",
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term, // search term
page: params.page
};
},
processResults: function (data, params) {
// 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.clientes
};
},
cache: true
},
//escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
minimumInputLength: 3,
theme: 'bootstrap'
});
</script>