dapper获取实体的集合
///linq处理集合,并通过Newtonsoft处理成json/// 获取表tb_sys_zhuowei所有数据 /// public IEnumerableSelectAll_tb_sys_zhuowei() { using (IDbConnection conn = OpenConnection()) { const string query = @"select * from tb_sys_zhuowei order by addtime desc"; return conn.Query (query, null); } }
protected string GetTree() { MyProject.DataOrm dao = new MyProject.DataOrm(); IEnumerablelist = dao.SelectAll_tb_sys_zhuowei(); var q = from x in list orderby x.louceng group x by x.louceng into g //按楼层分组 select new { name = g.Key.ToString() + "楼", open = true, children = from x2 in g orderby x2.quyu //where x2.louceng == g.Key group x2 by x2.quyu into k //按区域分组 select new { name = k.Key.Length == 2 ?
"包间" : k.Key + "区", click = "loadzw('" + g.Key.ToString() + "-" + k.Key + "')" } //select new //{ // name = x2.quyu.Length == 2 ? "包间" : x2.quyu + "区", // click = "loadzw('" + g.Key.ToString() + "-" + x2.quyu + "-" + x2.number.ToString() + "')" //} }; var templist = q.ToList(); return Newtonsoft.Json.JsonConvert.SerializeObject(templist, Newtonsoft.Json.Formatting.Indented); }
[{ "name": "1楼", "open": true, "children": [{ "name": "A区", "click": "loadzw('1-A')" }, { "name": "B区", "click": "loadzw('1-B')" }, { "name": "包间", "click": "loadzw('1-BJ')" }]},{ "name": "2楼", "open": true, "children": [{ "name": "A区", "click": "loadzw('2-A')" }]}]
前端ztree构建树
效果
版权声明:本文博客原创文章,博客,未经同意,不得转载。