Select2 не использует мои шаблоныРезультаты или параметры выбора шаблона

Я пытаюсь использовать select2 ajax-вызов с шаблонами. Я получаю ajax только в порядке, но он не использует мои функции шаблона.

данные ajax:

[
   {"name":"First thing","otherData":"asdfg"},
   {"name":"Second thing","otherData":"qqerr"},
   {"name":"third thing","otherData":"yerty"},
   {"name":"fourth thing","otherData":"hgjfgh"},
   {"name":"fifth thing","otherData":"fhgkk"}
]

код select2 (который я взял много от здесь):

FundSearch = {
    create: function (selector, theURL) {
      $(selector).select2({
        ajax: {
          url: theURL,
          dataType: 'json',
          delay: 250,
          data: function (params) {
            console.log(params.term);
            return {
              q: params.term, // search term
              page: params.page
            };
          },
          results: 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
            };
          },
          cache: true
        },
        escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
        minimumInputLength: 1,
        templateResult: formatData,
        templateSelection: formatDataSelection
      });

      function formatData (data) {
          if (data.loading) return data.name;

          markup = "<h1>" + data.name + "</h1>" + "<p>" + data.otherData + "</p>";

          return markup;
        }

        function formatDataSelection (data) {
          return data.name;
        }


    }
};

Ошибка, которую я получаю, составляет Uncaught TypeError: Cannot read property 'toUpperCase' of undefined в строке 356 из select2.js для версии: 3.5.2.

Мне кажется, что select2 не использует мою функцию templateSelection и templateResults.

Ответы

Ответ 2

В select2 3.5.2. это "formatResult" (единственное число, а не форматResults)