Javascript jquery-selectize.js更改了下拉列表标识问题
我想知道在存在多个选定下拉列表的地方,单击或更改了哪个下拉列表。我有两个集装箱,上面有国家和州的货物。我想做的是,当一个国家下拉列表被单击时,与单击的国家下拉列表在同一个容器中的状态下拉列表将被获取的数据填充 我的js代码如下Javascript jquery-selectize.js更改了下拉列表标识问题,javascript,jquery,ajax,selectize.js,Javascript,Jquery,Ajax,Selectize.js,我想知道在存在多个选定下拉列表的地方,单击或更改了哪个下拉列表。我有两个集装箱,上面有国家和州的货物。我想做的是,当一个国家下拉列表被单击时,与单击的国家下拉列表在同一个容器中的状态下拉列表将被获取的数据填充 我的js代码如下 var xhr , a; var country, $country; var city, $city; $country = $(".select2-country").selectize({ render: {
var xhr , a;
var country, $country;
var city, $city;
$country = $(".select2-country").selectize({
render: {
option: function(item, escape) {
var markup = "<div>";
if (item.value !== undefined && item.value != 0) {
markup += '<img width="25px" src="http://www.geonames.org/flags/x/' + item.value.toLowerCase() + '.gif" /> ';
}
markup += item.text;
markup += '</div>';
return markup;
}
},
onChange: function(value) {
if (!value.length) return;
console.log(this);
city.disable();
city.clearOptions();
city.load(function(callback) {
xhr && xhr.abort();
xhr = $.ajax({
url: draSite + '?index.php&option=com_dratransport&view=',
dataType: 'json',
data:{
selected: value,
task: 'getCities',
},
success: function(results) {
city.enable();
callback(results);
},
error: function() {
callback();
}
});
});
}
});
$city = $('.select2-city').selectize({
valueField: 'value',
labelField: 'text',
searchField: ['text'],
sortField: 'sort',
sortDirection: 'ASC',
diacritics:true,
});
city = $city[0].selectize;
//country = $country[0].selectize;
city.disable();
var-xhr,a;
var国家,$country;
var city,$city;
$country=$(“.select2 country”)。选择({
呈现:{
选项:功能(项目,转义){
var标记=”;
如果(item.value!==未定义&&item.value!=0){
标记+='';
}
标记+=item.text;
标记+='';
返回标记;
}
},
onChange:函数(值){
如果(!value.length)返回;
console.log(this);
城市。禁用();
city.clearpoptions();
加载(函数(回调){
xhr&&xhr.abort();
xhr=$.ajax({
url:draSite+'?index.php&option=com\u dratransport&view=',
数据类型:“json”,
数据:{
所选:值,
任务:“getCities”,
},
成功:功能(结果){
city.enable();
回调(结果);
},
错误:函数(){
回调();
}
});
});
}
});
$city=$('.select2 city')。选择({
valueField:'值',
labelField:“文本”,
搜索字段:[“文本”],
索特菲尔德:“排序”,
sortDirection:'ASC',
变音:没错,
});
城市=$city[0]。选择;
//国家=$country[0]。选择;
城市。禁用();
我就是这样做的。这是可行的,但我希望这是一个很好的方法
var xhr , a;
var country, $country;
var city, $city;
$country = $(".select2-country").selectize({
render: {
option: function(item, escape) {
var markup = "<div>";
if (item.value !== undefined && item.value != 0) {
markup += '<img width="25px" src="http://www.geonames.org/flags/x/' + item.value.toLowerCase() + '.gif" /> ';
}
markup += item.text;
markup += '</div>';
return markup;
}
},
onChange: function(value) {
city = $(this.$dropdown).parent().siblings('.select2-city')[0].selectize;
if (!value.length){city.clearOptions(); return;};
city.disable();
city.clearOptions();
city.load(function(callback) {
xhr && xhr.abort();
xhr = $.ajax({
url: draSite + '?index.php&option=com_dratransport&view=',
dataType: 'json',
data:{
selected: value,
task: 'getCities',
},
success: function(results) {
city.enable();
callback(results);
},
error: function() {
callback();
}
});
});
},
});
$city = $('.select2-city').selectize({
valueField: 'value',
labelField: 'text',
searchField: ['text'],
sortField: 'sort',
sortDirection: 'ASC',
diacritics:true,
});
for(var i = 0; i<$city.length; i++){
city = $city[i].selectize;
city.disable();
}
country = $country[0].selectize;
var-xhr,a;
var国家,$country;
var city,$city;
$country=$(“.select2 country”)。选择({
呈现:{
选项:功能(项目,转义){
var标记=”;
如果(item.value!==未定义&&item.value!=0){
标记+='';
}
标记+=item.text;
标记+='';
返回标记;
}
},
onChange:函数(值){
城市=$(此.$下拉列表).parent().sides('.select2 city')[0]。选择;
如果(!value.length){city.clearOptions();return;};
城市。禁用();
city.clearpoptions();
加载(函数(回调){
xhr&&xhr.abort();
xhr=$.ajax({
url:draSite+'?index.php&option=com\u dratransport&view=',
数据类型:“json”,
数据:{
所选:值,
任务:“getCities”,
},
成功:功能(结果){
city.enable();
回调(结果);
},
错误:函数(){
回调();
}
});
});
},
});
$city=$('.select2 city')。选择({
valueField:'值',
labelField:“文本”,
搜索字段:[“文本”],
索特菲尔德:“排序”,
sortDirection:'ASC',
变音:没错,
});
对于(var i=0;i我就是这样做的。这很有效,但我希望这是一个很好的方法
var xhr , a;
var country, $country;
var city, $city;
$country = $(".select2-country").selectize({
render: {
option: function(item, escape) {
var markup = "<div>";
if (item.value !== undefined && item.value != 0) {
markup += '<img width="25px" src="http://www.geonames.org/flags/x/' + item.value.toLowerCase() + '.gif" /> ';
}
markup += item.text;
markup += '</div>';
return markup;
}
},
onChange: function(value) {
city = $(this.$dropdown).parent().siblings('.select2-city')[0].selectize;
if (!value.length){city.clearOptions(); return;};
city.disable();
city.clearOptions();
city.load(function(callback) {
xhr && xhr.abort();
xhr = $.ajax({
url: draSite + '?index.php&option=com_dratransport&view=',
dataType: 'json',
data:{
selected: value,
task: 'getCities',
},
success: function(results) {
city.enable();
callback(results);
},
error: function() {
callback();
}
});
});
},
});
$city = $('.select2-city').selectize({
valueField: 'value',
labelField: 'text',
searchField: ['text'],
sortField: 'sort',
sortDirection: 'ASC',
diacritics:true,
});
for(var i = 0; i<$city.length; i++){
city = $city[i].selectize;
city.disable();
}
country = $country[0].selectize;
var-xhr,a;
var国家,$country;
var city,$city;
$country=$(“。选择2个国家