【问题标题】:Bloodhound limit not working猎犬限制不起作用
【发布时间】:2016-07-07 11:14:04
【问题描述】:

我正在使用以下代码在输入字段上启用 typeahead 有时这些区域没有显示,但是当我在检查元素中看到“网络 xhr 请求”时。 url 确实返回数据。

限制在此示例中不起作用的另一个问题。我尝试了不同的数字,但它们都不起作用

var Regions = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('label'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: {
        url: 'https://www.domain.com/getcities?query=%QUERY',wildcard: '%QUERY'
    },
    limit: 10
});
Regions.initialize();
var hotels = new Bloodhound({
    datumTokenizer: function (datum) {
        return Bloodhound.tokenizers.whitespace(datum.value);
    },
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: {
        url: 'https://www.domain.com/gethotels?query=%QUERY',
         wildcard: '%QUERY', 
    },
    limit: 10

});
hotels.initialize();

function typeAhead()
{



$('#myinput').typeahead({
      hint: true,
      highlight: true,
      minLength: 2
},
{
  name: 'nba-teams',
  displayKey: 'label',
  source: Regions.ttAdapter()  ,
  templates: {
    header: '<h3 class="league-name">Cities and regions</h3>'
  }
},
{
  name: 'nhl-teams',
   displayKey: 'label',
  source: hotels.ttAdapter()  ,
  templates: {
    header: '<h3 class="league-name">Hotels</h3>'
  }
});


}

【问题讨论】:

标签: typeahead bloodhound


【解决方案1】:

请检查以下代码。

var Regions = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('label'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: {
        url: 'https://www.domain.com/getcities?query=%QUERY',wildcard: '%QUERY'
    }
});
Regions.initialize();
var hotels = new Bloodhound({
    datumTokenizer: function (datum) {
        return Bloodhound.tokenizers.whitespace(datum.value);
    },
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: {
        url: 'https://www.domain.com/gethotels?query=%QUERY',
        wildcard: '%QUERY', 
    }
});
hotels.initialize();
function typeAhead(){
    $('#myinput').typeahead({
            hint: true,
            highlight: true,
            minLength: 2
        },
        {
            name: 'nba-teams',
            displayKey: 'label',
            source: Regions.ttAdapter()  ,
            limit: 10,
            templates: {
                header: '<h3 class="league-name">Cities and regions</h3>'
            }
        },
        {
            name: 'nhl-teams',
            displayKey: 'label',
            source: hotels.ttAdapter()  ,
            limit: 10,
            templates: {
            header: '<h3 class="league-name">Hotels</h3>'
        }
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-05
    • 2014-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多