提问人:fr332lanc3 提问时间:8/17/2022 更新时间:8/23/2022 访问量:83
Twitter typeahead.js未使用远程数据源初始化/按预期工作
Twitter typeahead.js not initializing / working as expected using remote data source
问:
Twitter typeahead 无法按预期工作,当我注释掉库中的代码时,我确实得到了一个非样式的建议下拉列表。
jQuery('input#test').typeahead(
{
hint: true,
highlight: true,
limit:25, //still using 5 which is default in the library
minLength: 3
},
{
name: 'customLookup',
source: function(query, result) {
return jQuery.ajax({
url: url, //my dynamic url, returns custom json array that needs to be mapped
data: 'shop_name=' + query + "&limit=25", //custom limit against backend api
dataType: "json",
type: "post",
success: function(data, textStatus, xhr) {
var suggestions = [];
jQuery.map(data.data, function(item){
suggestions.push(item.name + " - " + item.address);
});
result(suggestions); //stepping in, it just skips because syncCalled already = true? Then remove that code and it gives me back a list of 5 that isn't styled...
console.log(suggestions); //has array of strings as expected
},
error: function (request, status, error) {
alert(error);
}
});
}
});
那么,在配置时,是否有我错过捕获的选项或更新?使用需要将 JSON 映射到数组的后端自定义数据源,以便提前输入。
答:
0赞
fr332lanc3
8/23/2022
#1
只是直接修改了库并拥有我们自己的副本,不确定问题,但似乎可以很好地使用这种方法并使用自定义 CSS 进行样式设置。
评论