示例#1
0
        /// <summary>
        /// 获取所有的数据,填充TreeView
        /// </summary>
        /// <returns></returns>
        public async Task <JsonResult> GetTreeData()
        {
            try
            {
                List <Organization> list = await orgAppService.GetOrganizations();

                //修改数据格式,示例数据格式如下

                /*
                 * var str = "[
                 *              {'text': '父节点 1','id':4,'tags':['44'],'nodes':
                 *                  [
                 *                      {'text': '子节点 1','tags':['45'],'id':'2','nodes':
                 *                          [
                 *                              {'text': '孙子节点 1','tags':['42'],'id':'3'},
                 *                              {'text': '孙子节点 2','tags':['41'],'id':'8'}
                 *                          ]
                 *                      },
                 *                      {'text': '子节点 2','tags':['45'],'id':'7'}
                 *                  ]
                 *              }
                 *          ]";
                 */
                string strResult = "";
                if (list != null && list.Count > 0)
                {
                    strResult = GetChildNode(list, new List <Dictionary <string, object> >());
                }
                return(Json(new AjaxResponse()
                {
                    Success = true, Result = strResult
                }));
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                return(Json(new AjaxResponse {
                    Success = false, Result = ex.Message
                }));
            }
        }