我有html格式的sting值数据如何应用css和jquery样式
public class Menus
{
public List<Menus> GetALL { get; set; }
public int menuId { get; set; }
public string menuName { get; set; }
public string menuURL { get; set; }
public int parentId { get; set; }
}
public class MenuModel
{
public MenuItemsEntities objEntities = new MenuItemsEntities();
public string GetMenu()
{
//Get MainMenu Menus
Menus menuobj = new Menus();
var objmenu = from menus in objEntities.MenuItems
where menus.ParentId == 0
select menus;
string strMenuBuild = string.Empty;
strMenuBuild += "<ul>";
foreach (var i in objmenu)
{
menuobj.menuName = i.ItemName;
menuobj.menuId = i.MenuItemsID;
menuobj.menuURL = i.URL;
if (i.ParentId == 0)
{
//GetSubMenu();
strMenuBuild = strMenuBuild + "<li><a href='" + menuobj.menuURL + "'>" + menuobj.menuName + "</a><ul>";
strMenuBuild += GetSubMenu(Convert.ToInt32(menuobj.menuId)) + "</ul></li>";
//strMenuBuild += "</ul></li>";
}
}
strMenuBuild += "</ul>";
return strMenuBuild;
}
public string GetSubMenu(int submenuid)
{
string strSubBuild = string.Empty;
Menus menuobj = new Menus();
var submenu= from menus in objEntities.MenuItems
where menus.ParentId == submenuid
select menus;
if (submenu.Count() > 0)
{
foreach (var sbmnu in submenu)
{
menuobj.menuURL = sbmnu.URL;
menuobj.menuName = sbmnu.ItemName;
menuobj.menuId = sbmnu.MenuItemsID;
strSubBuild = strSubBuild + "<li ><a href='" + menuobj.menuURL + "'>" + menuobj.menuName + "</a>";
var submneu1 = from menus in objEntities.MenuItems
where menus.ParentId == menuobj.menuId
select menus;
if (submneu1.Count() > 0)
{
strSubBuild += "<ul>";
strSubBuild += GetSubMenu(Convert.ToInt32(menuobj.menuId));
strSubBuild += "</ul>";
}
strSubBuild += "</li>";
}
}
return strSubBuild;
}
}
我已经像
那样返回String In Html格式
但是我绑定了菜单和子菜单。我想应用css和jquery.how来应用Css和jquery我不知道。可以任何人帮助我...
答案 0 :(得分:1)
这是我用来建立菜单结构的功能:
var buildMenu = function(menu, el) {
var ul = $('<ul></ul>');
ul.appendTo(el);
for(var i in menu) {
var menuItem = $('<li><a href="' + menu[i].url + '">' + menu[i].title + '</a></li>');
menuItem.appendTo(ul);
if(menu[i].subMenu) {
buildMenu(menu[i].subMenu, menuItem);
};
};
}
菜单是包含菜单的jSON对象,el是div或包含插入菜单的元素。
我的菜单对象具有以下格式:
var menu : [{
title : 'Home',
url : 'Default.html'
}, {
title : 'Groups',
url : '#',
subMenu : [{
title : 'Group1',
url : 'Group1.html'
},{
title : 'Group2',
url : 'group2.html'
}]
}];
希望有所帮助