/// <summary> /// 返回 商户、分类Json树 /// </summary> /// <returns></returns> public ActionResult TreeJson() { DataTable dt = _productCategoryBLL.GetTree(); List <TreeJsonEntity> treeList = new List <TreeJsonEntity>(); TreeJsonEntity rootNode = new TreeJsonEntity(); rootNode.id = "0"; rootNode.text = "全部"; rootNode.value = "0"; rootNode.parentId = "-1"; rootNode.isexpand = true; rootNode.complete = true; rootNode.hasChildren = true; rootNode.img = "/Content/Images/Icon16/chart_organisation.png"; treeList.Add(rootNode); if (!DataHelper.IsExistRows(dt)) { foreach (DataRow row in dt.Rows) { string categoryId = row["CategoryId"].ToString(); bool hasChildren = false; DataTable childnode = DataHelper.GetNewDataTable(dt, "ParentId='" + categoryId + "'"); if (childnode.Rows.Count > 0) { hasChildren = true; } TreeJsonEntity tree = new TreeJsonEntity(); tree.id = categoryId; tree.text = row["CategoryName"].ToString(); tree.value = row["Code"].ToString(); tree.parentId = row["ParentId"].ToString(); tree.isexpand = true; tree.complete = true; tree.hasChildren = hasChildren; tree.img = "/Content/Images/Icon16/chart_organisation.png"; treeList.Add(tree); } } return(Content(treeList.TreeToJson("-1"))); }