jquery自动完成源函数请求发送者

时间:2012-05-16 15:42:51

标签: jquery-autocomplete

我正在使用jquery autocomplete

我尝试获取调用源值的控件(发件人)

我使用一个函数来获取我的列表。

类似的东西(看起来像):

$("#input").autocomplete({
    source: function (request, response) {
        $.post("/AjaxPostURL", request, response);
    }
}); 
sample From : http://stackoverflow.com/questions/1512607/how-do-i-set-jquery-

自动填充到后代替-的-获得

但我的是一个外部职能

我想在我的函数中捕获控件

有点像这样(看起来像):

 $("#input").autocomplete({
        source: myfunction (this)
        }
    }); 

myfunction = function (request, response, control ) {
            $.post("/AjaxPostURL", request, response);
            control.xxx
}

我需要保留请求和响应。但我也需要控制谁调用该功能。

我该怎么做?

坦克你


第2部分

我认为它应该看起来像

source: function( event, ui ) {     
        myfunction(event,ui ,$(this));
        }

问题:$目前不存在。 只有在调用函数时才会设置它。 并且它在我的函数上未定义(当shes调用时)。

1 个答案:

答案 0 :(得分:0)

使用 this.element 来获取来电者elememt, e.g。

source: function (request, response) {
    $.getJSON(myFunction(this.element, request.term),
       response);

另见: jQuery autocomplete: select Id from 'source' event