jquery - 使用 ajax 引导标签输入和预先输入
问题描述
我正在使用 Bootstraptagsinput
和typeahead
,当我以这种方式使用它时效果很好:
$(document).ready(function() {
$('.tagsinput-typeahead').tagsinput({
typeahead: {
source: $.getJSON('/ajax/tags.php'),
afterSelect: function() {
this.$element[0].value = '';
}
}
});
});
但我想将它与ajax一起使用,但它只显示第一个字母。
$(document).ready(function() {
jQuery('.tagsinput-typeahead').tagsinput({
typeahead : {
source: function (query, process) {
return jQuery.get('/ajax/tags.php?query=' + query, function(data){
// return process(data);
});
}
}
});
});
即使我回来process(data);
,它也不会起作用。
此外,当我单击一个建议时,该字母也会出现在输入字段中。
我的tags.php
样子是这样的:
$json = [];
$json[] = "test";
$json[] = 'Washington';
$json[] = 'London';
$json[] = 'Germany';
$json[] = 'Denmark';
echo json_encode($json);
有任何想法吗?
解决方案
推荐阅读
- javascript - 函数 moveDolly 中的 getWorldQuaternion 值返回 0 0 0 和 1,所以我只能在 Z 方向移动,我必须在头部方向移动
- python - Django 子模板未出现在输出的 html 中
- json - JQ中具有相同键的多行输出值
- c# - 如果值是元组,如何通过 .TryGetValue() 从字典中读取值?
- python-3.x - 带有 Google 服务帐户主题的 generate_access_token()
- html - 菜单上的梯形标签
- android - 高架基础安卓
- html - 将电子邮件另存为 PDF
- javascript - 对话框关闭时删除事件的问题(React useEffect)
- javascript - 递归不返回正确的结果