我有一个特殊情况: 当用户从自动完成jQuery中选择一个项目时,它将再次切换自动完成以获得另一组建议或一组源。我怎样才能做到这一点?以下是我的代码:
$('#JourneyStartLocation').autocomplete({
source: function (request, response) {
$.ajax({
url: '@Url.Action("AutocompleteFindLocation", "Home")',
type: "Get",
dataType: "json",
data: { SearchValue: $('#JourneyStartLocation').val(), Country: $('#JourneyCountryStart_code').val(), PcaId: $('#JourneyLocationStart_code').val() },
success: function (data) {
response($.map(data, function (item) {
return {
label: item.Name,
value: item.Name + "/" + item.EntityType + "/" + item.Latitude + "/" + item.Longitude + "/" + item.LocationId
}
}))
}
});
},
minLength: 2,
focus: function(event, ui) {
$("#JourneyStartLocation").val(ui.item.label);
return false;
},
select: function (event, ui) {
//splitting the selected item to assign values
var selectedItem = ui.item.value;
var values = selectedItem.split('/');
// assign values : name, entity type, latitude, longitude, lastId, next field
$('#JourneyStartLocation').val(values[0]);
$('#JourneyStartLocationTemp').val(values[0]);
$('#JourneyStartLocationEntityType').val(values[1]).trigger('change');
$('#JourneyStartLocationEntityTypeTemp').val(values[1]);
$('#JourneyStartLatitude').val(values[2]);
$('#JourneyStartLongitude').val(values[3]);
$('#StartLocationId').val(values[4]);
$('#JourneyLocationStart_code').val(values[5]);
$('#JourneyStartLocationNextField').val(values[6]);
// The special scenario here
if($('#JourneyStartLocationNextField').val() == "Find"){
//toggle autocomplete again for another set of suggestion
// or another set from source
}
return false;
}
});
非常感谢您的帮助。