Easy UI Tree操作

在Easy UI tree操作中,遇到了一系列问题

1.点击树传参数

 $('#featureTree').tree({
                url: 'GetFeatureTree?guid=',
                method: 'get',
                checkbox:true,
                animate: true,
                dnd: true,
                onBeforeLoad: function (node, param) {
                    //加载树前参数赋值参数
                    var guid = $('.roleGuid').val();
                    $('#featureTree').tree('options').url = "GetFeatureTree?guid=" + guid;
                },
            });

2. 能够拖动排序

$(function () {
        $('#tree').tree({
            url: 'GetDepartmentTree',
            method: 'get',
            animate: true,
            dnd: true,
            onClick: function (node) {//选中节点触发
                loadDepartment(node.id);
            },
            //拖动结束前触发
            onBeforeDrop: function (target, source, point) {
                //point: 'append','top' or 'bottom'.表示目标内上下
                //target: DOM object, The node being targeted for the drop.目标元素
                //source: the source node.拖动节点
                if (point != 'append') {
                    var place;
                    var targetNode = $(this).tree('getNode', target);
                    //获取位置
                    if (point == 'top') {
                        place = 0;
                    }
                    else//'bottom'
                    {
                        place = 1;
                    }
                    var startGuid = source.id;
                    var endGuid = targetNode.id;
                    $.ajax({
                        url: "DropTree",
                        type: "POST",
                        data: { "point": place, "startGuid": startGuid, "endGuid": endGuid },
                        datatype: "text",
                        success: function (result) {
                            if (result) {
                                return true;
                            }
                            else {
                                return false;
                            }
                        },
                        error: function () {
                            return false;
                        }
                    })

                }
                else {
                    $.messager.alert("提示", "不允许此操作");
                    return false;
                }
            }
        });
    })

3.后台递归算法(自动填写打勾)

#region 权限树
        public ContentResult GetFeatureTree(Guid? guid)
        {
            List<Feature> lisFeature = new List<Feature>();
            List<RoleFeature> lisRoleFeature = new List<RoleFeature>();
            FeatureArgs fArg = new FeatureArgs();
            if(guid != null)
            {
                lisRoleFeature = _RoleDAL.GetRoleFeature(guid.Value);
            }
            lisFeature = _FeatureDAL.GetFeatures(fArg);
            var nodestr = "{{\"id\":\"{0}\" ,\"text\": \"{1}\" ,\"checked\":{2},\"children\":[";
            var jsonstr = "[";
            if (lisFeature.Count > 0)
            {
                var rootNameList = lisFeature.Where(p => p.ParentGuid == null).ToList();
                foreach (var item in rootNameList)
                {
                    loadNodeOfFeature(lisFeature, item, nodestr, ref jsonstr, lisRoleFeature);
                }
                jsonstr = jsonstr.TrimEnd(',');
                jsonstr = jsonstr.TrimEnd('}');
                jsonstr = jsonstr.TrimEnd(']');
                jsonstr = jsonstr.TrimEnd(',');
                jsonstr += "]},";
            }
            else
            {
                jsonstr += "{}]";
            }
            jsonstr = jsonstr.TrimEnd(',');
            jsonstr += "]";
            return Content(jsonstr);
        }

        private void loadNodeOfFeature(List<Feature> lisFeature, Feature feature, string nodestr, ref string jsonstr, List<RoleFeature> lisRoleFeature)
        {
            string isChecked = "false";
            //判断是否需要打勾
            if (lisRoleFeature.Any() && lisRoleFeature.Any(o => o.FeatureGuid == feature.Guid))
            {
                isChecked = "true";
            }
            //增加子节点
            jsonstr += string.Format(nodestr, feature.Guid, feature.Title, isChecked);
            //判断节点是否有子节点
            var nodeNameList = lisFeature.Where(p => p.ParentGuid == feature.Guid).OrderBy(p => p.SortNo).ToList();
            if (nodeNameList.Any())
            {
                foreach (var item in nodeNameList)
                {
                    loadNodeOfFeature(lisFeature, item, nodestr, ref jsonstr, lisRoleFeature);
                }
                jsonstr = jsonstr.TrimEnd(',');
                jsonstr += "]},";
            }
            else
            {
                jsonstr += "]},";
            }
        }
        #endregion

 

转载于:https://www.cnblogs.com/guanwanli/p/7762258.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值