使用typeahead.js预取过滤器(使用基本选项)
Using Prefetch Filter with typeahead.js (Using basic options)
我使用typeahead.js。我正在使用预取选项,需要解析返回的数据。它不会抛出错误;它什么也没做。我找了一些例子,但没有一个使用Prefetch Filter选项。
预取文档链接
我的代码(不工作,但没有抛出错误):
$('#autocomplete').typeahead('destroy').typeahead( {
name: 'organizations',
prefetch: {
url: 'jsoncall',
filter: function() {
// Blatant hardcoded return value
return ['test-a','test-b','test'c];
}
}
}
);
My HTML:
<input id="autocomplete" class="large-12" autocomplete="off" type="text" placeholder="Enter school name">
我的困惑:
0________0
您可以通过filter
函数传递返回的数据,然后该函数会根据您的喜好解析数据。在上面的例子中,你可以这样做:
$('#autocomplete').typeahead({
name: 'organizations',
prefetch:
{
url: 'jsoncall',
filter: function(data){
// filter the returned data
return [data.movies[0].title, data.movies[1].title, data.movies[2].title];
}
}
}
);
如果返回的数据集是一个JSON对象,上面的例子可以工作,看起来像这样:
movies: [{id:12865, title:Kill Bill: Volume 1, year:2003, mpaa_rating:R, runtime:111,…},…]
0: {id:12865, title:Kill Bill: Volume 1, year:2003, mpaa_rating:R, runtime:111,…}
1: {id:12862, title:Kill Bill, Volume 2, year:2004, mpaa_rating:R, runtime:137,…}
2: {id:771237417, title:Kill Bill: The Whole Bloody Affair, year:2011, mpaa_rating:Unrated, runtime:,…}
3: {id:770998578, title:Angel of Death: Killer Nurse: A Bill Kurtis Special Report, year:2006,…}
4: {id:771352617, title:Kedi Billa Killadi Ranga, year:2013, mpaa_rating:Unrated, runtime:145,…}
total: 5
相关文章:
- 我的单元测试选项是什么
- 如何更改bigquery API中的计费层选项
- 使用Javascript获取所选选项ID
- Selectize.js:如何对整数值的选项进行排序
- 通过js在新选项卡中有条件地打开url
- 按照选项卡索引的顺序循环一个jQuery选择
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- 如何在使用selectBoxIt JQuery插件时检测选项更改
- 无法在Ionic select中预先选择最后一个选项
- 如何在选项卡上定义属性'的主窗口对象
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 使用此选项选择父类内部的类
- CKeditor:更改对话框中的默认选择选项
- JQuery覆盖不更改单选选项
- 活动选项卡's源代码-获取变量s值
- 绑定时将Parsley minlength消息作为选项传递时,未对其进行自定义
- Twitter Typeahead.js:点击/聚焦时显示所有选项
- Typeahead.js预取选项不起作用
- 关闭Typeahead.js的选项卡
- 使用typeahead.js预取过滤器(使用基本选项)