一直在尋找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」包含在ajax調用的大括號內,我是說在對象字面上不是函數調用。非常感激!你的「this.element.attr('id');」工作得很好!你搖滾! – eSteimann 2011-01-11 20:15:14