TypeAhead无法处理远程URL

时间:2016-02-01 20:18:45

标签: jquery json typeahead.js

我正在使用typeahead.js 0.11.1来实现自动完成功能。 JQuery版本是1.8.3

$(document).ready(function(){

       var engine = new Bloodhound({
          datumTokenizer: function (d) {d.communityName}, 
          queryTokenizer: Bloodhound.tokenizers.whitespace,
          remote: {
              'cache': false,
              url: '/portal/vcm/instituteSearch/%QUERY',
              wildcard: '%QUERY'
          }
      });

    $('#schools-suggestion-box').typeahead({
            hint: true,
            highlight: false,
            minLength: 3,
            offset: false
        },
        {
            source: engine,
            displayKey : 'communityName',
            templates: {
                 empty:function(data){
                    return '<div class="empty-message">unable to find any school or university that match the current query</div>';
                 },
                suggestion: function(data){

                    return '<div class="school-suggestions">' + data.communityName + '</div>';
                } 
            }
        }).on('typeahead:selected', function (obj, datum) {        
            window.location.href=datum.sessionInitiator;
        });

//end document ready

我面临的问题是,从服务器收到的所有结果都没有在UI上填充。如果有5条记录来自服务器,则只有3条记录显示在UI上。

另一个问题是,如果找到以搜索字符开头的结果,则只会在UI中显示该字符串。

如果我使用本地数组,一切都在UI中正常工作。

我已经读过,typeahead需要jquery版本1.9+但由于某些依赖,我无法切换到此版本。

0 个答案:

没有答案
相关问题