我正在使用autocomplete进行自动选择城市和地区的项目。我想现在动态自动选择所选城市的区域。尽管自动搜索工作得很好,但我还是无法为该地区发送动力城市。我该怎么做?我尝试了this stack answer中给出的选项,但没有用。我的代码到目前为止:
HTML 的
<input type="hidden" id="hid_search_city_id" name="hid_search_city_id" value="">
SCRIPT
$(document).ready(function(e) {
$("#hid_search_city_id").change(function() {
areas.setOptions({
params: {
entity_type: $('#hid_search_city_id').val()
}
});
});
});
var baseUrl = $('input#baseUrl').val();
var url = baseUrl + 'ajax/getSearchCities';
$('input#search_cities').autocomplete({
serviceUrl: url,
minChars: 1,
delimiter: /(,|;)\s*/,
maxHeight: 400,
width: 300,
deferRequestBy: 0,
onSelect: function(value, data) {
$('#id').val(+data);
$('#hid_search_city_id').val('');
$('#hid_search_city_id').val(data);
}
})
var url = baseUrl + 'ajax/getSearchAreas';
var areas = $('input#search_areas').autocomplete({
serviceUrl: url,
minChars: 1,
delimiter: /(,|;)\s*/,
maxHeight: 400,
width: 300,
params: {
entity_type: $('#hid_search_city_id').val()
},
deferRequestBy: 0,
onSearchStart: function(q) {
areas.entity_type = $('input#search_cities').val();
},
onSelect: function(value, data) {
$('#id').val(+data);
},
});
areas.setOptions({
params: {
entity_type: $('#hid_search_city_id').val()
}
});