php - 引导手风琴在 laravel 中无法动态正常工作
问题描述
我有一个引导手风琴左导航代码如下(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 的类进行 if 语句。即, if(div.class == something) 做其他事情做其他事情。如果可能的话,我可以解决这个问题。
解决方案
您不需要在那里循环子类别。只需使用:
@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 的新手,我推荐 checkout eloquent
推荐阅读
- python - 在fabric2 Connection中,如何在fab命令行中使用hosts参数
- android - 表单编码方法必须至少包含一个@Field
- sql - 按多列和多行条件查找sql查询
- ftp - 无法使用流集将 JSON 响应转储到 CSV 文件中的 FTP 服务器
- spring-boot - 403 Forbidden on using JWT Authorization in springboot
- python - 小黄人游戏 - 解释一下?
- python - pygame.quit()、quit() 或 run = False?
- google-analytics - 如何从 Bigquery 中的 Google 分析导出中查询智能目标?
- javascript - 未捕获的类型错误:sel.add 不是函数
- python - Windows 10 上未解决的导入“MySQLdb”