【发布时间】:2016-04-05 08:59:14
【问题描述】:
我需要从我的数据库中动态获取数据(作为用户类型)。我曾尝试查看typeahead
示例,但我不明白如何实现远程实现。
<div id="remote">
<input class="typeahead" type="text" placeholder="Oscar winners for Best Picture">
</div>
$('#the-basics .typeahead').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'states',
source: substringMatcher(states)
});
这要求数组states 存在于本地。但我需要从我的服务器端脚本中获取数据。我怎么能这样做?
【问题讨论】:
-
你应该试试这个例子 - twitter.github.io/typeahead.js/examples/#remote
-
@Dekay
source: bestPictures这里是什么? -
这是上面创建
Bloodhound对象的变量的名称...这个Bloodhound对象描述了您的数据将如何被访问 -
您还需要将 typeahead budle 包含为 js 资源
typeahead.bundle.js (bloodhound.js + typeahead.jquery.js)它需要 jQuery 1.9+ -
@aashna 你找到答案了吗?
标签: javascript typeahead.js twitter-typeahead