推特预先输入的bloodhound代币不起作用



令牌不起作用,当我键入"east"、"home"或"trap"时,应该建议使用"Inkoopverenigingen",怎么了?

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>

这就是解决方案:

        datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.tokens.join(' ')); },

仅举一例,engine.clearPrefetchCache();如果JSON文件在此期间发生了更改,则非常重要。

相关内容

  • 没有找到相关文章

最新更新