问题
I am pretty new in JS and in jQuery. In my work I came across a jQuery code from the jQuery UI Autocomplete widget that I do not fully understand. I have a two questions about this code which are separated into several posts (As recommended in that meta post). Also, sorry if my English is horrible, I'm doing my best. :)
Here is the code: http://pastebin.com/NyG48Yb9
What I DO understand:
- The
autocomplete
function operates on someinput
, in our case - the#searchBox
. The function get as parameter an object that represents the behavior of the list when the user types into the#searchBox
. - The object has a key named
source
which describes the resource that provides the list.
What I DO NOT understand #1:
The value of the source
key is a callback function that gets two parameters: request
and response
. According to the jQuery UI Autocomplete API Documentation, the second parameter is:
A response callback
which means that it is a function. Now, according to that tutorial about callback functions (Yeah, I did some research :D) there is a function A and a function B. Function A gets as a parmeter a variable that contains a reference to a function that is specified to be function B when we call function A, and function B is executed in the scope of function A.
In my code, function A is the anonymous function in the source
key, and the response
is the callback function. But I cannot find any implementation of the response
function.
My question:
Where does the response
function is implemented? And where can I fine a documentation?
Thank you very much. :)
My other question: In jQuery UI Autocomplete, what data sources can the `source` key hold?
回答1:
The implementation of response
is present in jquery-ui.js. Its their internal function. To know its implementation you will have to download uncompressed jquery-ui.js and will have to locate autocomplete
related code.
来源:https://stackoverflow.com/questions/32141272/in-jquery-ui-autocomplete-where-does-the-response-function-is-implemented