标签:datarow select user view 子菜单 sel pre auth _id
1、根据添加到数据库的菜单转换json
以最笨的方法写的,这个里面的可以进行简写
public string GetListCategoryString() { string sql = "select * from T_WX_Category where sale_id=1 and p_id=0"; DataTable dt = DbHelperSQL.Query(sql).Tables[0]; string json = "{‘button‘:[{‘type‘: ‘scancode_waitmsg‘, ‘name‘: ‘xss‘, ‘key‘: ‘qrcode‘},"; //主菜单 foreach (DataRow row in dt.Rows) { json += "{‘name‘:‘" + row["cate_name"] + "‘"; //子菜单 string sqls = "select * from T_WX_Category where sale_id=1 and p_id=" + row["id"]; DataTable dts = DbHelperSQL.Query(sqls).Tables[0]; if (dts.Rows.Count > 0) { json += ",‘sub_button‘:["; foreach (DataRow rows in dts.Rows) { if (dts.Rows.IndexOf(rows) == dts.Rows.Count - 1) { //最后一行 json += "{ ‘type‘:‘scancode_waitmsg‘,‘name‘: ‘" + rows["cate_name"] + "‘,‘key‘: ‘qty‘}]},"; } else { json += "{ ‘type‘:‘scancode_waitmsg‘,‘name‘: ‘" + rows["cate_name"] + "‘,‘key‘: ‘qty‘},"; } } } else { json += "}"; } } json += ",{‘type‘: ‘view‘, ‘name‘: ‘我‘, ‘url‘: ‘http://wm.risingtec.com.cn/OAuthRedirectUri.aspx?type=user‘}]}"; return json; }
标签:datarow select user view 子菜单 sel pre auth _id
原文地址:http://www.cnblogs.com/mengluo/p/7784939.html