ajax 给 easyui-tree 赋值

前端之家收集整理的这篇文章主要介绍了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;
    }

猜你在找的Ajax相关文章