Javascript TypeAhead不';不显示查询结果
我非常绝望 我有这个问题与引导打字提前 HTML标记:Javascript TypeAhead不';不显示查询结果,javascript,php,html,mysql,bootstrap-typeahead,Javascript,Php,Html,Mysql,Bootstrap Typeahead,我非常绝望 我有这个问题与引导打字提前 HTML标记: <div class="form-group"> <label for="">Recipients</label> <input id="recipients" name="recipients" autocomplete="off" class="form-control" data-role="tagsinput"> &
<div class="form-group">
<label for="">Recipients</label>
<input id="recipients" name="recipients"
autocomplete="off"
class="form-control"
data-role="tagsinput">
</div>
$('#recipientsContainer').tagsinput({
allowDuplicates: false,
trimValue: true,
confirmKeys: [13, 44],
typeahead: {
hint: true,
highlight: true,
minLength: 4,
limit: 10,
source: function (query) {
$.ajax({
url: "/app/route",
type: 'POST',
dataType: 'JSON',
data: {'query' : query},
success: function(data) {
console.log(data);
return(data);
}
});
},
afterSelect: function() {
this.$element[0].value = '';
}
}
});
["Justin Demetria +393281893574", "Dylan Alea +393700488191", "Zahir Tatyana +393007841301", "Ryan Veda +393542236060", "Hunter Wanda +393393156943"]
在Ajax调用之后,我在控制台中得到了这个数组:
<div class="form-group">
<label for="">Recipients</label>
<input id="recipients" name="recipients"
autocomplete="off"
class="form-control"
data-role="tagsinput">
</div>
$('#recipientsContainer').tagsinput({
allowDuplicates: false,
trimValue: true,
confirmKeys: [13, 44],
typeahead: {
hint: true,
highlight: true,
minLength: 4,
limit: 10,
source: function (query) {
$.ajax({
url: "/app/route",
type: 'POST',
dataType: 'JSON',
data: {'query' : query},
success: function(data) {
console.log(data);
return(data);
}
});
},
afterSelect: function() {
this.$element[0].value = '';
}
}
});
["Justin Demetria +393281893574", "Dylan Alea +393700488191", "Zahir Tatyana +393007841301", "Ryan Veda +393542236060", "Hunter Wanda +393393156943"]
问题是:我什么也看不到:(什么也看不到。typeahead不工作
在控制台中,我得到了这个错误
bootstrap-tagsinput.js Uncaught TypeError: Cannot read property 'success' of undefined.
我怎样才能修好它
我使用的是Bootstrap 3,最后一个Typeahead js源代码。对于Typeahead,使用猎犬获取数据,而不是ajax 您的代码应该如下所示:
var customers = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/api/customers?query=%QUERY',
wildcard: '%QUERY'
}
});
$('#customer').typeahead({
minLength: 3,
highlight: true
}, {
name: 'customers',
display: 'name',
source: customers
}).on("typeahead:select", function(e, customer) {
vm.customerId = customer.id;
});
有关猎犬的更多信息:
这里有一些typeahead的例子:James,现在我的ajax调用是:
$('#recipientsContainer').tagsinput({
allowDuplicates: false,
trimValue: true,
confirmKeys: [13, 44],
typeahead: {
source: function(queryForHints) {
if (queryForHints.length < 4)
return '';
var parameters = {'queryForHints': queryForHints};
jQuery.ajax({
url: "/app/route",
data: parameters,
type: "POST",
dataType: "json",
success: function(data) {
var sourceData = [];
for (var i = 0; i < data.length; i++) {
sourceData.push(data[i].text);
}
return (sourceData);
},
error: function(data) {
console.log("error for xxxxx/xxxxx");
},
async: true
});
}
}
});
错误出现在bootstrap-tagsinput.js第331行,我发现:
if ($.isFunction(data.success)) {
// support for Angular callbacks
data.success(processItems);
我们能解决这个问题吗
以我的拙见,问题在于输入标记无法理解ajax调用的成功我阅读了您的所有代码,但我不明白如何在标记输入函数(如我的代码)中使用它…你能为我提供更多帮助吗?非常感谢..你不必使用tagsinput函数,只需使用我代码中的typeahead函数,并指定api中记录的行为。如果我将你的代码放在我的页面中,例如,我会收到以下错误:Hound未定义Oh my fault…对于这种typeahead,你需要安装e twitter typeahead Nuget包运行正常h:(另一个我不知道的组件:(如果我找到它,你能帮我使它符合我的需要吗?