我有以下javascript代码 - 我想在onSelect()回调函数中使用'term'$ _GET变量。
任何人都可以解释我是怎么做到的吗?我试图在回调中使用console.log,但这似乎不起作用。
$('#org_search_term, #org_search_postcode').autocomplete({
serviceUrl: '<?php echo $this->getUrl('rp/organisation/search', array('_secure' => true)) ?>',
paramName:'term',
minChars: 3,
deferRequestBy: 500,
dataType: 'json',
onSearchStart: function(){
$('#org_search_term, #org_search_postcode').addClass('loading');
},
onSearchComplete: function(){
$('#org_search_term, #org_search_postcode').removeClass('loading');
},
onSearchError: function(){
$('#org_search_term, #org_search_postcode').removeClass('loading');
},
onSelect: function(selected, data) {
console.log(this); // this doesn't seem to work
},
transformResult: function (response) {
var results = { suggestions:[] };
if (!response.totalRecords)
return false;
$.each(response.items, function(i, item){
results.suggestions.push({
value: item.organisation_name+', '+item.street+', '+item.town+', '+item.county+', '+item.postcode+', '+item.country,
data: item.organisation_id,
organisation_name: item.organisation_name
});
});
// add the catch all result
results.suggestions.push({
value: '<?php echo $this->__('My org is not listed') ?>',
data: null,
organisation_name: null
});
return results;
}
});
答案 0 :(得分:1)
看看@ Jquery autocomplete on select event
select: function (event, ui) {
var label = ui.item.label;
var value = ui.item.value;
}