ajax 给 easyui-tree 赋值

html

   <ul id="Menu" class="easyui-tree" style="width: 100%; padding: 0 0 0 0; margin: 0 0 0 0;"
            data-options="fit:true,dnd:false">
        </ul>

js

  function BuildMenu() {
            $.ajax({
                url: "ashx/MainMenuHandler.ashx",
                success: function (ret) {
                    treedata = eval("(" + ret + ")");
                   
                    $("#Menu").tree({ data: treedata, onClick: function (node) {
                        if (node.url != "") {
                           // OpenTab(node.text, node.url);   打开菜单
                        }
                        else if (node.motion != "") {
                            eval(node.motion);
                        }
                    }
                    });

                },
                error: function (err) {
                    alert(err);
                }
            });         
        }


ashx

  private string CreateMenu(int Level, string ParentMenuCode, DBOperate dbo)
    {

        string strResult = "[";
        string strMysql = "select * from vUserMenu where loginname=@loginname and  ParentMenuCode=@ParentMenuCode order by orderindex";

        SqlParameter[] pas ={ 
                DBOperate.MakeInParam("@loginname", CurrentUser.LoginName),
                DBOperate.MakeInParam("@ParentMenuCode",ParentMenuCode)};
        
        DataTable dt = dbo.ExecuteTable(strMysql, pas, CommandType.Text);

        if (CurrentUser.OrgCountyID == "")
        { 
        }
        int i = 0;
        foreach (DataRow row in dt.Rows)
        {
            string strItem = "'id':'{0}','text':'{1}','iconCls':'{2}','children':{3},'url':'{4}','motion':'{5}'";

            string strId = row["menucode"].ToString();//Level.ToString() + i.ToString(); 
            string strUrl = Lib.EncodeUrlParas(row["url"].ToString());
            strUrl = strUrl.Replace("$sys_dir$", virtualPath);
            string strMenuName = row["MenuName"].ToString();
            string strMenuCode = row["MenuCode"].ToString();
            string strCLS = row["ICON"].ToString();
            string strMotion = row["functionScript"].ToString();
            string strChild = "[]";
            if (Level < 1)
            {
                strChild = CreateMenu(Level + 1, strMenuCode, dbo); //有子菜单,递归调用               
            }
            
            strItem = string.Format(strItem, new string[] { strId, strMenuName, strCLS,strChild,strUrl,strMotion });
            
            if (dt.Rows.IndexOf(row)>0)
                strResult += ",";

            strResult += "{" + strItem + "}";
        }
        strResult  +="]";            
        return strResult;
    }



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值