0

嗨,我在将我的 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;
            }
        }
    });
};
4

1 回答 1

1

我错过了构造函数中的空值。

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

固定版本

return $field.typeahead(null, {
        minLength: spec.minChars,
        displayKey: 'value',
        source: suggestions.ttAdapter(),
});
于 2014-10-15T16:45:39.980 回答