mah*_*man 9 twitter ajax json typeahead.js
我正在使用带有ajax调用的twitter typeahead(typeahead.js 0.11.1)插件,但是当ajax结果的数量小于限制时,会给出一些奇怪的行为(默认限制为5,我没有指定在预先打电话中).这是我如何设置它:
var limit = 6;
populate_typeahead = function() {
$('.typeahead').typeahead('destroy');
$('.typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
source: ajaxquery,
});
};
var ajaxquery = function(query, syncresults, process) {
return $.ajax({
url: $(this)[0].$el.closest('span.twitter-typeahead').find('input:last').data('mahiFindByPath'),
type: 'get',
data: {search_string: query, limit: limit},
dataType: 'json',
success: function(json) {
return typeof json.options == 'undefined' ? false : process(json.options);
}
});
};
Run Code Online (Sandbox Code Playgroud)
导致我出现此问题的实际示例是在输入框中键入"new to",它返回以下json.options:
[
'new to add to g1',
'new to be in grp1 then remove from grp',
'new to drag',
'new to assign'
]
Run Code Online (Sandbox Code Playgroud)
但是,当所有4个应该显示时,出现的唯一建议是"新添加到g1".如果我继续输入'new to d',则会出现'new to drag'建议.如果我只键入'new',那么我会收到完整的5条建议,包括上面的大部分内容!
如果我改变var limit = 5;
那么ajax调用只返回最多5个结果,并且建议列表根本没有显示,直到我得到'新到',即'new'没有给出任何建议.这让我觉得它与ajax结果的数量小于或等于typeahead限制有关.为了测试我的理论,我将5个无意义的项目推送到json.options数组中,因此总是有超过5个结果,并且它们都按预期工作 - 只是我不想总是在列表底部有无意义的建议.任何建议非常感谢!
agu*_*taf 25
我遇到了类似的问题.它看起来像是Typeahead版本0.11.1中的一个错误.在这里尝试解决方案:https: //github.com/twitter/typeahead.js/pull/1212 ,看看是否有效.
具体的变化如下:https: //github.com/per-nilsson/typeahead.js/commit/387290b1e70be0052c6dd9be84069f55d54a7ce7
归档时间: |
|
查看次数: |
7647 次 |
最近记录: |