gpt4 book ai didi

jquery-select2 - Select2 加载远程数据示例不起作用

转载 作者:行者123 更新时间:2023-12-04 16:43:48 26 4
gpt4 key购买 nike

这个例子根本不起作用..有人可以在jfiddle中创建这个吗????

这是示例站点。
https://select2.github.io/examples.html
十分感谢你的帮助!!!

enter image description here

最佳答案

为此找到了答案。请参阅以下示例。希望这对其他人有帮助!

这是Fiddle

这是脚本:

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

var markup = '<div class="clearfix">' +
'<div class="col-sm-1">' +
'<img src="' + repo.owner.avatar_url + '" style="max-width: 100%" />' +
'</div>' +
'<div clas="col-sm-10">' +
'<div class="clearfix">' +
'<div class="col-sm-6">' + repo.full_name + '</div>' +
'<div class="col-sm-3"><i class="fa fa-code-fork"></i> ' + repo.forks_count + '</div>' +
'<div class="col-sm-2"><i class="fa fa-star"></i> ' + repo.stargazers_count + '</div>' +
'</div>';

if (repo.description) {
markup += '<div>' + repo.description + '</div>';
}

markup += '</div></div>';

return markup;
}

function formatRepoSelection (repo) {
return repo.full_name || repo.text;
}

$(document).ready(function(){

$(".js-data-example-ajax").select2({
ajax: {
url: "https://api.github.com/search/repositories",
dataType: 'json',
delay: 250,
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.items
};
},
cache: true
},
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
minimumInputLength: 1,
templateResult: formatRepo, // omitted for brevity, see the source of this page
templateSelection: formatRepoSelection // omitted for brevity, see the source of this page

});
});

更新:

I see this question has been getting a lot of visits lately. Please note the jfiddle links no longer work.

关于jquery-select2 - Select2 加载远程数据示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29807324/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com