use*_*796 8 jquery jquery-ui jquery-autocomplete jquery-ui-autocomplete
我一直在研究这个问题,似乎无处可去.基本上我在类的一堆输入上有自动完成,但是我需要获取特定的输入id来构建对象以发布ajax(我必须为这个项目使用POST而不是GET).
$(".input_autocomplete").autocomplete({
source: function( request, response ) {
// here is where I get the hash from local storage,
// reference the id and build the object
// tried this.id, $(this).prop('id'), no luck
$.ajax({
url: '/somepath/filename.htm',
contentType: 'application/json',
dataType: 'json',
type: 'POST',
data: JSON.stringify(obj),
success: function(json) {
return {
label: item.label,
value: item.label
}
},
error: function() {
// error handling
}
}); // ajax
} // source
});
Run Code Online (Sandbox Code Playgroud)
And*_*ker 12
尝试:
$(this.element).prop("id");
Run Code Online (Sandbox Code Playgroud)
要么:
this.element[0].id;
Run Code Online (Sandbox Code Playgroud)
在source回调内部,this指的是小部件实例.为了获得小部件附加到的元素,您应该使用this.element,这是一个jQuery对象.