Closed xiaolongyuan closed 10 years ago
UI文档已找到 能否出一个省市区级联例子
$(function() {
$(".form-biz-customer-customer-inputBasic").data("formOptions", {
bindEvents : function() {
var $form = $(this);
var $branchProvince= $form.find("input[name='branchProvince']");
var $branchCity= $form.find("input[name='branchCity']");
var $branchCounty= $form.find("input[name='branchCounty']");
$branchProvince.select2({
placeholder: "选择所在省",
allowClear: true,
minimumInputLength: 0,
multiple:false,
ajax: {
url:WEB_ROOT+ "/sys/data-dict!findByPrimaryKey.json?primaryKey=ADMINISTRATIVE_REGION_CN",
dataType: 'json',
data: function (term, page) {
return {
q: term
};
},
results: function (data, page) {
var rst=[];
//修改成合适的数据格式 [{id:text}]
$.each(data, function(i, n){
rst.push({id:i,text:n});
});
return { results: rst };
}
}
});
$branchCity.select2({
placeholder: "选择城市",
allowClear: true,
minimumInputLength: 0,
multiple:false,
ajax: {
url:function (){
var val = $branchProvince.select2("val");
if(val==''){
return '#';
}
return WEB_ROOT+ "/sys/data-dict!findByPrimaryKey.json?primaryKey="+val;
},
dataType: 'json',
data: function (term, page) {
return {
q: term
};
},
results: function (data, page) {
var rst=[];
//修改成合适的数据格式 [{id:text}]
$.each(data, function(i, n){
rst.push({id:i,text:n});
});
return { results: rst };
}
}
});
$branchCounty.select2({
placeholder: "选择区县",
allowClear: true,
minimumInputLength: 0,
multiple:false,
ajax: {
url:function (){
var val = $branchCity.select2("val");
if(val==''){
return '#';
}
return WEB_ROOT+ "/sys/data-dict!findByPrimaryKey.json?primaryKey="+val;
},
dataType: 'json',
data: function (term, page) {
return {
q: term
};
},
results: function (data, page) {
var rst=[];
//修改成合适的数据格式 [{id:text}]
$.each(data, function(i, n){
rst.push({id:i,text:n});
});
return { results: rst };
}
}
});
$branchProvince.on("change", function(e) {
alert("change "+JSON.stringify({val:e.val, added:e.added, removed:e.removed}));
})
.on("select2-removed", function(e){
alert("change "+JSON.stringify({val:e.val, added:e.added, removed:e.removed}));
});
}
});
});