没有猎犬的先行者

时间:2016-06-12 19:48:11

标签: javascript jquery ajax typeahead

我的印象是,在进行远程通话时我不需要使用猎犬。我试过运行这段代码:

$("#iban2").typeahead({
    hint: false,
    minLength: 4,
    highlight: true
},
{
    source: function show(q, cb, cba) {
        console.log(q);
        var url = '@Url.HttpRouteUrl("DefaultApi", new {controller = "Iban"})' + "/" + q;
        $.ajax({ url: url })
            .done(function(res) {
                cba(res);
            })
            .fail(function(err) {
                alert(err);
            });
    },
    displayKey: 'iban'
});

即使我得到结果,从源函数中调用async cb仍然不起作用。有关正在发生的事情的任何提示?

感谢。

路易斯

1 个答案:

答案 0 :(得分:1)

不确定原因,但添加限制选项似乎可以解决问题:

$("#iban2").typeahead({
    hint: false,
    minLength: 4,
    highlight: true
},
{
    source: function show(q, cb, cba) {
        console.log(q);
        var url = '@Url.HttpRouteUrl("DefaultApi", new {controller = "Iban"})' + "/" + q;
        $.ajax({ url: url })
            .done(function(res) {
                cba(res);
            })
            .fail(function(err) {
                alert(err);
            });
    },
    limit:10,
    displayKey: 'iban'
});