【问题标题】:Typeahead.js displaying only 5 optionsTypeahead.js 仅显示 5 个选项
【发布时间】:2016-08-23 03:37:44
【问题描述】:

如何增加 typeahead 中的选项数量?

下面是我的代码:

    var substringMatcher = function (strs) {
    return function findMatches(q, cb) {
        var matches, substringRegex;

        // an array that will be populated with substring matches
        matches = [];

        // regex used to determine if a string contains the substring `q`
        substrRegex = new RegExp(q, 'i');

        // iterate through the pool of strings and for any string that
        // contains the substring `q`, add it to the `matches` array
        $.each(strs, function (i, str) {
            if (substrRegex.test(str)) {
                matches.push(str);
            }
        });

        cb(matches);
    };
};

$(function () {
    $.get('@Url.Action("getApplications")',function (data) {
        //console.log(data);
        $('#the-basics #Appl_ShortName_textbox').typeahead(
        {
            hint: false,
            highlight: false,
            minLength: 1,
            minLimit: 10,
            maxLimit: 10
        },
    {
        name: 'data',
        source: substringMatcher(data)
    });
    });
});

【问题讨论】:

    标签: asp.net-mvc typeahead.js


    【解决方案1】:

    在“source: substringMatcher(data)”下添加“limit: (无论你想要显示的最大项目数)”。

    例如:

     source: substringMatcher(data),
     limit: 20
    

    将产生一个最多包含 20 个项目的下拉菜单。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-16
      • 2014-08-02
      • 2016-09-28
      • 2018-10-02
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多