递归的使用案例

 

递归找treeview树可以用如下方法:

public JsonResult GetExpenseCatalogConfDataTree()
{
List<ExpenseCatalogConfModel> list = _serviceExpenseAccount.GetExpenseCatalogConfModelList(Guid.Empty); //根节点
foreach(var model in list)
{
  FindExpenseCatalogConfList(model, model.ExpenseCatalogConfID);//调用递归方法
}
  return Json(list, JsonRequestBehavior.AllowGet);
}

public void FindExpenseCatalogConfList(ExpenseCatalogConfModel model,Guid parentId)
{
var findList = _serviceExpenseAccount.GetExpenseCatalogConfModelList(parentId);
foreach (var findmodel in findList)
{
FindExpenseCatalogConfList(findmodel, findmodel.ExpenseCatalogConfID);
}
model.ChirldList = findList;//对找到的结果赋值
}

posted @ 2017-12-13 14:39  飞刀软件  阅读(122)  评论(0编辑  收藏  举报