我有一个正确的狂躁日试图找出如何发布密钥而不是输入字段的值。
Jquery的
jQuery( document ).ready(function() {
jQuery("#autocomplete").autocomplete({
source: function (request, response) {
jQuery.ajax({
url: "{{URL('/autocomplete')}}",
data: {
autocomplete: this.term
},
success: function (data) {
console.log(data[0]['label']);
response( jQuery.map( data, function( item ) {
return {
label: item.label,
value: item.id
};
}));
},
//This does not get picked up?
select: function(event, ui){
alert('this is not firing on select?');
jQuery('#hidden').val(ui.item.value);
}
});
},
});
我已经更新了代码,但仍然无法将密钥推送到select的隐藏字段。
实时预览(在位置搜索中键入Stoke) http://isca01.bigwavemedia.info/~hospita2/crawler/public/index.php/search
答案 0 :(得分:0)
jQuery( document ).ready(function() {
jQuery("#autocomplete").autocomplete({
source: function (request, response) {
jQuery.ajax({
url: "{{URL('/autocomplete')}}",
data: {
autocomplete: this.term
},
success: function (data) {
response( jQuery.map( data, function( item ) {
return {
label: item.label,
value: item.label,
key: item.id
};
}));
},
});
},
select: function(event, ui){
console.log('something selected');
jQuery('#hidden').val(ui.item.key);
//jQuery('input[name="autocomplete"]').val(ui.item.label);
jQuery('#autocomplete').attr({
value: ui.item.label
});
console.log(ui.item.label);
console.log(jQuery('input[name="autocomplete"]').val() + "this is the result of above");
}
});
});