【问题标题】:Upgrading typeahead from 0.9.3 to 0.10.5 remote将 typeahead 从 0.9.3 升级到 0.10.5 远程
【发布时间】:2014-10-15 15:29:07
【问题描述】:

您好,我在将 typeahead js 从 0.9.3 升级到 0.10.5 时遇到了麻烦。它在 0.9.3 中工作,但我似乎无法让我的远程连接在最新版本中工作。

我正在使用以下代码。

init = function(spec) {
    var $field;

    $field = $(document.getElementById(spec.id));

    var suggestions = new Bloodhound({

        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
        queryTokenizer: Bloodhound.tokenizers.whitespace,

        remote: {
            url: spec.url,
            replace: function(uri, query) {
                return extendURL(uri, {
                    "t:input": query
                });
            },
            filter: function(response) {
                return response.matches;
            }
        }
    });

    suggestions.initialize();

    return $field.typeahead({
        limit: 5,
        displayKey: 'value',
        source: suggestions.ttAdapter()
    });
};
return exports = init;

在 0.9.2 中,以下代码有效,但由于某种原因,每次您在输入框中按下键时,建议都会消失,直到 keyup 匹配。我希望这次升级能解决我的问题,或者可能是配置问题导致了它。

init = function(spec) {
    var $field;

    $field = $(document.getElementById(spec.id));
    return $field.typeahead({
        minLength: spec.minChars,
        limit: 5,
        remote: {
            url: spec.url,
            replace: function(uri, query) {
                return extendURL(uri, {
                    "t:input": query
                });
            },
            filter: function(response) {
                return response.matches;
            }
        }
    });
};

【问题讨论】:

    标签: javascript jquery typeahead.js twitter-typeahead bloodhound


    【解决方案1】:

    我在构造函数中遗漏了 null。

    return $field.typeahead({
            limit: 5,
            displayKey: 'value',
            source: suggestions.ttAdapter()
    });
    

    固定版本

    return $field.typeahead(null, {
            minLength: spec.minChars,
            displayKey: 'value',
            source: suggestions.ttAdapter(),
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-15
      • 1970-01-01
      • 2022-07-22
      • 2015-11-26
      相关资源
      最近更新 更多