小编Mat*_*pen的帖子

Twitter使用"prefetch"时没有结果,但使用"远程"JSON

我整天都在苦苦挣扎.我的先行搜索表达式与远程json数据完美配合.但是当我尝试使用与预取数据相同的json数据时,建议是空的.在点击第一个符号后,我得到预定义的消息"无法找到任何东西..."以获得空结果.

这是我的脚本:

function initialTypeaheadTest(){
    var mo_selector = $('*[data-moT="mysearch"]');
    var engine = new Bloodhound({
        limit: 10
        ,prefetch: {url:'/api/action/getjsontest'}
        //,remote: {url:'/api/action/getjsontest'}
        ,datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name')
        ,queryTokenizer: Bloodhound.tokenizers.whitespace
    });
    engine.clearPrefetchCache(); //  only for test purposes
    engine.initialize();

    mo_selector.typeahead(
        {
            hint: true,
            highlight: true,
            minLength: 1
        }, {
        name: 'engine',
        displayKey: 'name',
        source: engine.ttAdapter(),
            templates: {
                empty: [
                    '<div class="empty-message">',
                    'unable to find anything that match the current query',
                    '</div>'
                ].join('\n'),
                suggestion: Handlebars.compile([
                        '<div id="{{value}}"><p style="max-height:100%;"><strong>{{title}}</strong></p>',
                        '<span style="font-size:12px;">{{year}}</span></div>'
                    ].join(''))
            }
    });
}
Run Code Online (Sandbox Code Playgroud)

那就是我的json:

[{
"year":"02 Feb 2013 …
Run Code Online (Sandbox Code Playgroud)

jquery json bootstrap-typeahead twitter-typeahead

5
推荐指数
1
解决办法
729
查看次数