0

我想让 jquery 的自动完成对自定义事件起作用。我可能需要调整源代码。我试图理解它,但不确定它是如何'function( request, response )'工作的。这是如何被调用的以及参数来自哪里?

_initSource: function() {
        var array, url,
            that = this;
        if ( $.isArray(this.options.source) ) {
            array = this.options.source;
            this.source = function( request, response ) {
                response( $.ui.autocomplete.filter( array, request.term ) );
            };
        } else if ( typeof this.options.source === "string" ) {
            url = this.options.source;
            this.source = function( request, response ) {
                if ( that.xhr ) {
                    that.xhr.abort();
                }
                that.xhr = $.ajax({
                    url: url,
                    data: request,
                    dataType: "json",
                    success: function( data ) {
                        response( data );
                    },
                    error: function() {
                        response( [] );
                    }
                });
            };
        } else {
            this.source = this.options.source;
        }
    }
4

1 回答 1

1

它是从自动完成中的不同方法调用的。

像这儿 :

this.source( { term: value }, this._response() );

它在 _search 方法中。

于 2013-09-18T11:45:22.423 回答