我正在尝试编辑此类别导航视图。我需要的是:
对于ex,导航系统现在的工作原理如下:
或
我们想要的是:
或
热门(已选中)
外套
@model CategoryNavigationModel
@using Nop.Web.Models.Catalog;
@using Nop.Core.Infrastructure;
@functions{
public bool BreadCrumbContainsCurrentCategoryId(CategorySimpleModel category)
{
if (Model.CurrentCategoryId == 0)
return false;
if (category.Id == Model.CurrentCategoryId)
return true;
foreach (var subCategory in category.SubCategories)
{
if (BreadCrumbContainsCurrentCategoryId(subCategory))
{
return true;
}
}
return false;
}
}
@helper RenderCategoryLine(CategorySimpleModel category)
{
var _categoryService = EngineContext.Current.Resolve<Nop.Services.Catalog.ICategoryService>();
// additional check on whether to set an active class on the parents of the current categories and above. Meaning all categories from the
// breadcrumb will have an "active" class
bool active = false;
if (category.Id == Model.CurrentCategoryId || category.SubCategories.Count(BreadCrumbContainsCurrentCategoryId) > 0)
{
active = true;
}
<li class="@(active ? "active" : "inactive")">
@if (category.ParentCategoryId == Model.CurrentCategoryId || category.Id == Model.CurrentCategoryId)
{
<a href="@Url.RouteUrl("Category", new { SeName = category.SeName })">@category.Name
@if (category.NumberOfProducts.HasValue)
{
<text> </text>@T("Categories.TotalProducts", category.NumberOfProducts.Value)
}
</a>
}
@{
if (category.Id == Model.CurrentCategoryId ||
category.SubCategories.Count(BreadCrumbContainsCurrentCategoryId) > 0)
{
if (category.SubCategories.Count > 0)
{
<ul class="sublist">
@foreach (var subCategory in category.SubCategories)
{
@RenderCategoryLine(subCategory)
}
</ul>
}
}
}
</li>
}
@if (Model.Categories.Count > 0)
{
<div class="block block-category-navigation">
<div class="title">
@if (Model.CurrentCategoryId == 1 || Model.CurrentCategoryId == 3 || Model.CurrentCategoryId == 4 || Model.CurrentCategoryId == 5)
{
<strong>@T("Categories")</strong>
}
else
{
<a href="javascript:void(0)" onclick="event.preventDefault(); history.back(1);"><strong><< Geri Dön</strong></a>
}
</div>
<div class="listbox">
<ul class="list">
@foreach (var category in Model.Categories)
{
@RenderCategoryLine(category)
}
</ul>
</div>
</div>
}
我的代码是这样的,但是有一个问题。当所选类别没有子类别时,代码不起作用。在这种情况下,它必须做这样的事情:
PS:运动衫没有子类别。
相反,它显示了这样的东西:
我希望我能解释一下自己。我该如何解决这个问题?
感谢。