zoukankan      html  css  js  c++  java
  • jquery 多级联动下拉列表含(数据模型)

    方法

    /**
     * 级联
     * 联动
     * @param url:访问json数据的地址
     * @param param:参数
     * @param levelIds:页面下拉标签数组,为联动级数
     * @private
     */
    function _yh_linkage(url,params, levelIds){
        _yh_postRequest(url,params,function(response){
            //console.log(response);
            /**
             * 初始下拉列表数据
             * @param obj
             * @returns {jQuery}
             */
            function objInit(obj){
                return $('#'+obj).html('<option value="">请选择</option>');
            }
            selectToChildOption(response,levelIds,0);
    
            /**
             * 递归联动初始数据
             * @param object:数据
             * @param levelIds:联动下拉框id数组
             * @param levelIndex:第几级下拉列表
             */
            function selectToChildOption(object,levelIds,levelIndex){
                for (var index in levelIds) {
                    if(index<levelIndex) continue;
                    objInit(levelIds[index]);
                }
                if( object == null  ) return ;
                if( levelIds == null || levelIds.length <= levelIndex ) return ;
                if( object != null && object.list != null ) {
                    $.each(object.list,function(i,o){
                        $('#'+levelIds[levelIndex]).append('<option value="'+o.id+'" >'+o.name+'</option>');
                    });
                    $('#'+levelIds[levelIndex]).change(function() {
                        var n = $('#'+levelIds[levelIndex]).get(0).selectedIndex-1;
                        selectToChildOption(object.list[n], levelIds, levelIndex + 1);
                    });
                }
            }
        });
    }

    需要用到的另一函数

    /**
     * post请求
     * @param url
     * @param params
     * @param callbackfunciton:回调函数
     * @returns
     */
    function _yh_postRequest(url,params,callbackFunction){
        //console.log(params);
        if(params == null ){
            params = {};
        }
        $.post(url,params,function(response){
            if( callbackFunction != null)
                callbackFunction(response);
        });
    }

    java

    public class TKY {
        private String id;
        private String name;
        private boolean select= false;//是否默认选中
        private List<TKY> list = new ArrayList<>();
        
        public TKY(String id ,String name){
            this.id = id;
            this.name = name;
        }
    
        public String getId() {
            return id;
        }
    
        public String getName() {
            return name;
        }
    
        public List<TKY> getList() {
            return list;
        }
    
        public void addList(TKY t) {
            list.add(t);
        }
    
        public boolean isSelect() {
            return select;
        }
    
        public void setSelect(boolean select) {
            this.select = select;
        }
        
    }
  • 相关阅读:
    December 23rd 2016 Week 52nd Friday
    December 22nd 2016 Week 52nd Thursday
    December 21st 2016 Week 52nd Wednesday
    December 20th 2016 Week 52nd Tuesday
    December 19th 2016 Week 52nd Sunday
    December 18th 2016 Week 52nd Sunday
    uva294(唯一分解定理)
    uva11624Fire!(bfs)
    fzu2150Fire Game(双起点bfs)
    poj3276Face The Right Way
  • 原文地址:https://www.cnblogs.com/hwaggLee/p/7285675.html
Copyright © 2011-2022 走看看