码迷,mamicode.com
首页 > 其他好文 > 详细

下拉树的公共插件

时间:2018-07-06 23:31:47      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:show   dev   input   query   this   compare   点击事件   htm   turn   

/**
 * 公共的设备型号的下拉
 */
function pubModel(id){
    var list=getEqumentList();
    $(list).each(function(idx,ele){
        $("#"+id).append(‘<option value="‘+this.id+‘">‘+this.text+‘</option>‘);
    })
}
function getEqumentList() {
    var equmentList = [];
    $.ajaxSetup({async : false});
    $.post("Filter_listEqument.action", {        
    }, function(respData, status) {
        var resultList = respData.resultList;
        if (resultList != null)
            for (var i=0; i<resultList.length; ++i)
                equmentList.push(eval("("+resultList[i]+")"));
    }, "json");
    $.ajaxSetup({async : true});
    return equmentList;
}

/**
 * 公共的设备状态的下拉
 */
function pubDevState(id){
    var list=[{‘id‘:‘0‘,‘text‘:‘正常‘}, {‘id‘:‘1‘,‘text‘:‘停用‘}, {‘id‘:‘2‘,‘text‘:‘故障‘}]
    $(list).each(function(idx,ele){
        $("#"+id).append(‘<option value="‘+this.id+‘">‘+this.text+‘</option>‘);
    })
}
/**
 * 公共的抄表类型下拉
 */
function pubReadType(id){
    var list=[{id:0,text:‘数采‘},{id:1,text:‘手抄‘}];
    $(list).each(function(idx,ele){
        $("#"+id).append(‘<option value="‘+this.id+‘">‘+this.text+‘</option>‘);
    })
}
/**
 * 公共的部门的下拉
 */
;(function($){
    var me;//input输入框
    var selectId="";
    $.fn.buildButtomTree=function(data,_id){
        selectId=!!_id?_id:"";
        if(_id){
            this.val(depObj[_id]);
            this.attr("departmentval",depObj[_id]);
        }
        // var data=[
        //     {id: "101001", name: "计划财务部", pId: "001", code: "101001"},
        //     {id: "105001", name: "港吉", pId: "001", code: "105001"},
        //     {id: "001", name: "整个公司", pId: "000", code: "001"}
        // ]
        //构建html
        var str=
            ‘<div class="menuContent" style="display:none;overflow:auto">‘+
                ‘<ul id="treeDemo" class="ztree" style="margin-top:0;width:177px"></ul>‘+
            ‘</div>‘;
        this.parent().append(str);
        this.click(function(){
            showMenu();
        })
        initTreeData(data,this);
    }
    var initTreeData=function(zNodes,el){
        me=el;
        var setting = {
            view: {
                selectedMulti: false //是否允许多选
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                //zTree节点的点击事件
                onClick: function(e, treeId, treeNode){
                    var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
                    nodes = zTree.getSelectedNodes();
                    var v = "",c="";
                    nodes.sort(function compare(a,b){return a.id-b.id;});
                    for (var i=0, l=nodes.length; i<l; i++) {
                        v += nodes[i].name + ",";
                        //v += nodes[i].name;
                        //c += nodes[i].code + ",";
                        c += nodes[i].code;
                    }
                    if (v.length > 0 ) v = v.substring(0, v.length-1);
                    var cityObj =me;
                    cityObj.val(v);
                    cityObj.attr("departmentval", c);
                    hideMenu();
                }
            }
        };
        //var $tree=el.next().find(".ztree");
        $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        if(!!selectId){
            var node=zTree.getNodeByParam("id",selectId);
            console.log(node);
            //设置选中
            zTree.selectNode(node);
        }
        
        zTree.expandAll(true);
        
    }
    var hideMenu=function(){
        me.next().fadeOut("fast");
        $("body").unbind("mousedown", onBodyDown);
    }
    var onBodyDown=function(){
        if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
            hideMenu();
        }
    }
    var showMenu=function(){
        me.next().slideDown("fast");
        $("body").bind("mousedown", onBodyDown);
    }
})(jQuery);

 

下拉树的公共插件

标签:show   dev   input   query   this   compare   点击事件   htm   turn   

原文地址:https://www.cnblogs.com/pengfei25/p/9275734.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!