我想通过加载远程数据将 select2 添加到 jquery 查询生成器。
这是我的代码https://jsfiddle.net/cxz2m3y7/22/:
$('#builder-widgets').queryBuilder({
plugins: ['bt-tooltip-errors'],
filters: [{
id: 'category',
label: 'select2',
type: 'string',
plugin: 'select2',
plugin_config: {
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, 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.items,
pagination: {
more: (params.page * 30) < data.total_count
}
};
},
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
},
valueSetter: function(rule, value) {}
}],
rules: rules_widgets
})
select2 已正确加载,但是当我编写时未加载 ajax 源。为什么不加载ajax源?