jquery自动完成源代码说明

时间:2013-09-18 11:21:31

标签: javascript jquery

我想让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;
        }
    }

1 个答案:

答案 0 :(得分:1)

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

喜欢这里:

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

它在_search方法中。

相关问题