繁体   English   中英

select2列表未填充

[英]select2 list not being populated

我在使用select2填充列表时遇到问题。 这就是我到目前为止所得到的。 浏览器调试器中没有错误。 刚刚返回“没有找到结果”。 有什么建议么?

$(document).ready(function () {

   //The url we will send our get request to
   var attendeeUrl = '/Schedule/getCourses';
   var pageSize = 20;

$(".test").select2({
    ajax: {
        url: attendeeUrl,
        dataType: 'json',
        delay: 250,
        type: 'GET',
        data: function (params) {
            return {
                searchTerm: params.term,
                size: pageSize,
                page: params.pageSize
            };
        },
        processResults: function (data, params) {
            params.page = params.page || 1;

            return {
                results: data.text
            };
        },
        cache: true
    },
    escapeMarkup: function (markup) { return markup; }, 
    minimumInputLength: 1
 });
});

我必须包括以下内容。

templateResult: formatRepo,
templateSelection: formatRepoSelection

以及以下功能。

function formatRepo(repo) {
   if (repo.loading) return repo.text;

   var markup = '<div class="asd">' + repo.CourseCode +
   '</div>';
   markup += '</div></div>';
   return markup;
}
function formatRepoSelection2(repo) {
    return repo.full_name || repo.text;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM