typeahead error无法调用undefined的方法'replace'

时间:2013-12-20 14:16:56

标签: jquery typeahead.js

typeahead.min.js 0.9.3

我收到错误:

我从后端调用搜索框的数据,以使搜索数据始终保持更新状态:

$('#searchbox').typeahead({
    limit: 10,
    minLength: 2,
    remote: function(query, process) {
        $.ajax({
            url: '/typeahead',
            type: "GET",
            data: {'s': $('#searchbox').val() },
            success: function(result) {
                console.log(result);
                return process(result.names);
            },
            dataType: 'json'
        });
    },
    updater: function(item) {
        var values = $('#searchbox').data('values');
        alert(values);
        for (var index in values) {
            if (values[index].name == item) {
                location.href = values[index].href;
                break;
            }
        }
        return item;
    }
});

我得到的错误如下:

Uncaught TypeError: Cannot call method 'replace' of undefined typeahead.min.js:347
utils.mixin.get typeahead.min.js:347
x.isFunction.i jquery.js:4
utils.mixin.getSuggestions typeahead.min.js:530
x.isFunction.i jquery.js:4
(anonymous function) typeahead.min.js:995
x.extend.each jquery.js:4
utils.mixin._getSuggestions typeahead.min.js:994
x.isFunction.i jquery.js:4
EventTarget.trigger typeahead.min.js:162
x.isFunction.i jquery.js:4
utils.mixin._compareQueryToInputValue typeahead.min.js:609
x.isFunction.i jquery.js:4
x.event.dispatch jquery.js:5
y.handle

现在我真的不知道要改变什么或错误在哪里。有人有想法吗?

1 个答案:

答案 0 :(得分:1)

我从未见过像这样的远程选项的语法。 docs要求它为URL,这是我一直使用的。所以你的要求是这样的:

remote: '/typeahead?s=%QUERY',

我也从未见过updater选项,因此我不确定这是否会按预期运行。