- //创建GoodsClassInfo类
- //创建GoodsType类
- public class GoodsType
- {
- public GoodsType()
- {
- GoodsList = new List<GoodsClassInfo>();
- }
- public int TypeId { get; set; }
- public IList<GoodsClassInfo> GoodsList { get; set; }
- }
- //方法
- public GoodsType[] SearchTypeList(ISettings settings)
- {
- var conn = settings.Systems.Current.ConnectionString;
- using (var db = DBCreate.CreateDb_GoodsWEB(classname, conn) as IDBGoodsWEB)
- {
- IDbTable table = db.GetGoodsClassList();
- Dictionary<int, GoodsType> _coll = new Dictionary<int, GoodsType>();
- foreach (DbReaderRow r in table)
- {
- int level = Convert.ToInt32(r["LEVELNUM"]);
- int id = Convert.ToInt32(r["ID"]);
- string className = r["CLASSNAME"].ToString();
- string classId = r["CLASSID"].ToString();
- int lastClassId = Convert.ToInt32(r["LASTCLASSID"]);
- DateTime createTime = (DateTime)r["CREATETIME"];
- int sort = Convert.ToInt32(r["SORT"]);
- int isDelete = Convert.ToInt32(r["ISDELETE"]);
- if (!_coll.ContainsKey(level))
- {
- _coll.Add(level, new GoodsType { TypeId = level });
- }
- _coll[level].GoodsList.Add(new GoodsClassInfo
- {
- ID = id,
- CLASSNAME = className,
- CLASSID = classId,
- LASTCLASSID = lastClassId,
- LEVELNUM = level,
- CREATETIME = createTime,
- SORT = sort,
- ISDELETE = isDelete
- });
- }
- return _coll.Values.ToArray<GoodsType>();
- }
- }
- //前台页面脚本
- $(function () {
- var bar = $('#sidebar');
- bar.html('');
- $.json(
- { __DLL: 'Hebccc.GoodsManager.BLL', __METHOD: '.GoodsWEB.Operate.SearchTypeList', _SESSION: false },
- function (obj) {
- eval('var objData=' + obj);
- var level0 = objData[0];
- var level1 = objData[1];
- var level2 = objData[2];
- for (var i = 0; i < level0.GoodsList.length; i++) {
- var id0 = level0.GoodsList[i].ID;//id0标记最外层div的id,0级分类
- var name0 = level0.GoodsList[i].CLASSNAME;
- var sideid = '_divsidelist' + id0;
- var divHtml = $('<div id="' + sideid + '" class="sidelist"></div>');
- divHtml.append('<span><h3><a href="javascript:void(0)">' + name0 + '</a></h3></span>');
- var layer = $('<div class="i-list" ><dl></dl></div>').appendTo(divHtml);
- for (var j = 0; j < level1.GoodsList.length; j++) {
- var id1 = level1.GoodsList[j].ID; //id1标记1级分类
- var name1 = level1.GoodsList[j].CLASSNAME;
- var lastclass1 = level1.GoodsList[j].LASTCLASSID;
- if (lastclass1 != id0) { continue; }
- var asd = $('<asd></asd>');
- asd.append('<dt><a href="search.aspx?type=' + id1 + '">' + name1 + '</a></dt>');
- var dd = $('<dd><ul></ul></dd>').appendTo(asd);
- for (var k = 0; k < level2.GoodsList.length; k++) {
- var id2 = level2.GoodsList[k].ID; //id2标记2级分类
- var name2 = level2.GoodsList[k].CLASSNAME;
- var lastclass2 = level2.GoodsList[k].LASTCLASSID;
- if (lastclass2 != id1) { continue; }
- var subNav = '<subNav> | <a href="search.aspx?type=' + id2 + '">' + name2 + '</a></subNav>';
- dd.children().append(subNav);
- }
- layer.children().append(asd);
- }
- bar.append(divHtml);
- }
- $('.sidelist', '#sidebar').mousemove(function () { $(this).find('.i-list').show(); $(this).find('h3').addClass('hover'); });
- $('.sidelist', '#sidebar').mouseleave(function () { $(this).find('.i-list').hide(); $(this).find('h3').removeClass('hover'); });
- });
- });
转载于:https://blog.51cto.com/doubleqian/656270