【发布时间】:2017-06-15 05:36:44
【问题描述】:
我正在使用我的 MVC 应用程序实现最新版本的预输入。情况是,我得到了 json 结果,结果很好且经过验证。
在 typeahead 的返回部分,我放了一个警报,我可以看到所有返回的结果都在那里。但是在显示方面,什么都没有显示。控制台中也没有错误消息。 XHR 完全没问题。
坦率地说,我不知道为什么会这样?你能给我任何想法吗..提前谢谢
使用的预输入版本:0.11.1
以下是我的代码..
<div class="tt-container">
<input id="customer" name="customer" type="text" value="" class="form-control" required />
</div>
Typeahead 声明
var customers = new Bloodhound({
datumTokenizer: function (d) { return Bloodhound.tokenizers.whitespace(d.value); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: '/api/customer?query=%QUERY',
wildcard: '%QUERY',
filter: function(customers) {
//debugger;
return $.map(customers,function(user) {
//debugger;
alert(user.customerName);
return {
value: user.customerName
};
});
}
},
ajax: {
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: function(jqXhr, settings) {
var authHeaders;
// pull apart jqXHR, set authHeaders to what it should be
//debugger;
jqXhr.setRequestHeader('Access-Control-Allow-Origin', '*');
}
}
});
customers.initialize();
$('#customer').typeahead({
minLength: 3,
highlight: true
},
{
name: 'customers',
displayKey: 'value',
source: customers.ttAdapter()
});
【问题讨论】: