我有一个引导式左手风琴导航代码,如下所示(html,css,row),它工作正常。基本上是类别和子类别。但是,当尝试使用php laravel使其动态时,它在设计中无法正常工作。这意味着它会破坏CSS。
<div class="left-sidebar">
<h2>Category</h2>
<div class="panel-group category-products" id="accordian"><!--category-productsr-->
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordian" href="#sportswear">
<span class="badge pull-right"><i class="fa fa-plus"></i></span>
Sportswear
</a>
</h4>
</div>
<div id="sportswear" class="panel-collapse collapse">
<div class="panel-body">
<ul>
<li><a href="">Nike </a></li>
<li><a href="">Under Armour </a></li>
<li><a href="">Adidas </a></li>
<li><a href="">Puma</a></li>
<li><a href="">ASICS </a></li>
</ul>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><a href="#">Kids</a></h4>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><a href="#">Fashion</a></h4>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><a href="#">Households</a></h4>
</div>
</div>
</div><!--/category-productsr-->
</div>
在谷歌搜索和重新谷歌搜索之后,我到达了附近,了解我的解决方案。但是,现在我面临的问题是-对于该具有子类别的类别,我有一个fa fa-plus图标类。它正确显示了具有子类别的类别。但是它显示的时间与当前子类别的时间相同-如果一个类别有两个子类别,则显示两个+图标;如果某个类别具有3/4/5子类别,则它们分别显示3 + / 4 + / 5 +图标而不是展示一个。我该怎么办?
<div class="left-sidebar">
<h2>Category</h2>
<div class="panel-group category-products" id="accordian"><!--category-productsr-->
<?php
$category = DB::table('tbl_category')
->where('publication_status', 1)
->get();
$subcategory = DB::table('tbl_sub_category')
->where('publication_status', 1)
->get();
?>
@foreach ($category as $v_cat)
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordian" href="#{{$v_cat->category_id}}">
<?php echo $v_cat->category_name; ?>
@foreach($subcategory as $sub)
@if ($sub->category_id === $v_cat->category_id)
<span class="{{ $v_cat->category_id === $sub->category_id ? "badge pull-right" : '' }}"><i class="{{ $v_cat->category_id === $sub->category_id ? 'fa fa-plus' : '' }}"></i></span>
@endif
@endforeach
</a>
</h4>
</div>
<div id="{{$v_cat->category_id}}" class="panel-collapse collapse">
<div class="panel-body">
<ul>
<li class="panel panel-title"><a href="{{URL::to('/flowers-category/'.$v_cat->category_name)}}">{{$v_cat->category_name}} Link </a></li>
</ul>
<span class="info info-sign"><i>Subcategory</i></span>
<ul>
@foreach($subcategory as $sub)
@if ($sub->category_id === $v_cat->category_id)
<li><a href="{{URL::to('/flowers-sub-category/'.$sub->sub_category_name)}}">{{$sub->sub_category_name}}</a></li>
@endif
@endforeach
</ul>
</div>
</div>
</div>
@endforeach
</div><!--/category-productsr-->
注意:是否有任何过程可检查div该div使用哪个类。是否可以使用div类制作if语句。即if(div.class == some)做其他事情。如果可能的话,我也许可以解决问题。
答案 0 :(得分:0)
您不需要在那里循环子类别。只需使用:
@if ($subcategory->where('category_id', $v_cat->category_id)->first())
<span class="badge pull-right"><i class="fa fa-plus"></i></span>
@endif
此行检查类别是否具有子类别。
@if ($subcategory->where('category_id', $v_cat->category_id)->first())
如果您不熟悉laravel,建议您结帐eloquent