1

https://select2.github.io/examples.html#data-ajax

select2の場合、私はしたい:

  1. いくつかの初期選択をリストします。小さなリストの場合は、直接選択できます。
  2. リモートで長い/より多くの選択肢を検索します。

ajaxしかし、両方をdata同時に指定することはできないようです。

なにか提案を?ありがとう。


コードスニペットが追加されました

function installShopSelect2() {
    var url = "/ajax/brandEnterprise/findShops.mapi";
    "use strict";
    $('#shopid').select2({
        ajax: {
            type: "GET",
            url: url,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            delay: 250,
            //async: false,
            data: function (params) {
                return {
                    keyword: params.term,
                    besId: selectedBes,
                    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, except to indicate that infinite
                // scrolling can be used
                params.page = params.page || 1;

                return {
                    results: data,
                    pagination: {
                        more: (params.page * 30) < data.total_count
                    }
                };
            },
            cache: true
        },
        escapeMarkup: function (markup) {
            return markup;
        },
        //data: $.getJSON(url, {besId: selectedBes, keyword: ''}, function (data) {
        //    return {results: data};
        //}),
        placeholder: "--Please search--",
        minimumInputLength: 2,
        allowClear: true
    });
}
4

1 に答える 1