xautlx / s2jh

A Java/J2EE development framework for enterprise system based on Struts/Spring/JPA/Hibernate and jquery/bootstrap
GNU Lesser General Public License v3.0
321 stars 242 forks source link

下拉框级联选择有参照么?另此框架UI文档能否告知 #91

Closed xiaolongyuan closed 10 years ago

xiaolongyuan commented 10 years ago

image

xiaolongyuan commented 10 years ago

UI文档已找到 能否出一个省市区级联例子

xiaolongyuan commented 10 years ago

$(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})); 
           });

    }
});

});