1
令牌不工作,當我輸入「東」,「家」或「陷阱」,應該提出「Inkoopverenigingen」,有什麼不對?Twitter的預輸入令牌獵犬不工作
JSON:
[
{
"value": "Inkoopverenigingen",
"tokens": [
"inkoopverenigingen",
"inwoopverenigingen",
"east",
"home",
"trap"
]
},
{
"value": "Aannemers - Afbraakwerken",
"tokens": [
"West",
"Side",
"Story"
]
},
{
"value": "Affichageondernemingen",
"tokens": [
"West",
"Side",
"Story"
]
},
{
"value": "Aanwervingsbureaus",
"tokens": [
"West",
"Side",
"Story"
]
}
]
的javascript:
var engine = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
limit: 15,
prefetch: 'data/typeahead/what.json',
remote: 'data/typeahead/queries/%QUERY.json'
});
engine.initialize();
engine.clearPrefetchCache();
var template_source = $("#entry-template-what").html();
$('.test .typeahead-what').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: 'what',
displayKey: 'value',
// `ttAdapter` wraps the suggestion engine in an adapter that
// is compatible with the typeahead jQuery plugin
source: engine.ttAdapter(),
templates: {
empty: no_results,
suggestion: Handlebars.compile(template_source)
}
}
);
HTML:
<div class="test">
<input type="text" class="typeahead-what form-control" id="section" name="section">
</div>
HTML模板:
<script id="entry-template-what" type="text/x-handlebars-template">
<div>
<strong>{{value}}</strong>
<div class="controls pull-right">
<span class="glyphicon glyphicon-plus"></span>
<span class="glyphicon glyphicon-minus"></span>
</div>
</div>