3

我正在使用 rails3-jquery-autocomplete gem。一切都很漂亮。

我现在唯一的问题是弄清楚当自动完成文本没有匹配项时如何显示“不匹配”消息。

我是新手——我看过这些类似的回复(这里这里,但似乎仍然无法弄清楚。

谢谢!

4

1 回答 1

1

我做了这样的事情:


jQuery(".auto_search_complete").live("click", function() {
var $this = jQuery(this);
     $this.autocomplete({
        minLength: 3,

        source: function (request, response) {
        jQuery.ajax({
            url: "/autocomplete.json",
            data: {
            term: request.term
            },
            success: function (data) {
            if (data.length == 0) {
// You would enter a return for printing "No Response" here.
// I did:
    //  $this.siblings('span.guest_email').show();
          //      $this.siblings('span.delete_button').show();

            }
            response(data);
            }
        });
        },
// ... Rest of your stuff here, like focus, select... this above bit is your answer....

我使用jQuery是因为我的 $ 被原型占用了,所以我不得不有所不同。

因此请注意,您必须使用长格式的 ajax 请求,而不是花哨的快速请求,因为您想将成功分解为“如果没有数据子句”

于 2012-09-07T01:56:22.367 回答