Jquery UI의 자동 완성 (v1.8.5)을 살펴보면서 추가 매개 변수를 보내고 다른 입력란을 자동 채우기 위해 여분의 데이터를 촬영할 때 문서가 부족하다는 것을 깨달았습니다. 내가 가지고있는 것은 진실이지만, 그런 해킹처럼 보인다 ... 이것을 개선하는 방법에 관한 어떤 생각?Jquery UI 자동 완성 여분의 매개 변수 및 자동 채우기 - 좌절 된 해결책
<script type="text/javascript">
var optofirst = {
width: 375,
// doing "$(this)" here fails
source: function(request, response) {
// grab the calling element
// "$(this)" here works but ya gotta dig to get to the ID
var cat = $(this);
var callid = cat[0].element.context.id; //digging away
$.ajax({
// doing "$(this)" here fails
url: "automagic.php",
dataType: "json",
data: {
term : request.term,
//send its ID to the php script
grab : callid,
},
success: function(data) {
response($.map(data, function(item) {
return {
// start assigning item handles to the response
label: item.first,
value: item.first,
last: item.last,
}
}));
}
});
},
select: function(event, ui) {
console.log(ui.item ?
"Selected: " + ui.item.last :
"Nothing selected, input was " + this.value);
// make #lname have the value last name
// the "item" in this case appears to get its info from the handles assign in "success:"
$("#flyover #lname").attr("value",ui.item.last);
},
minLength: 2,
};
$("#flyover #fname").autocomplete(optofirst);
</script>
감사 앤드류를 사용하여 레일 3.1에서이 작업을 수행하고 싶어! 실제로 도움이되었습니다. 아약스 호출에 중괄호 안에 "this"를 포함하는 방법을 생각하지 않았습니다. 함수 호출이 아니라 개체 리터럴에서 말하는 것입니다. 매우 감사! 귀하의 "this.element.attr ('id');" 잘 일 했어! 너 락! – eSteimann