我试图在Laravel中循环播放一个菜单。
我将嵌套数组传递给主刀片模板categories-management.blade.php
。
View::make('categories-management')->with('categories', $categories);
$categories
array (size=3)
'Business Resources' =>
array (size=7)
'Operations' =>
array (size=4)
'resource_type_id' => int 1
27 =>
array (size=3)
'id' => int 27
'name' => string 'Design & Development' (length=20)
'children' =>
array (size=2)
... truncated ...
然后我用categories-management.blade.php
踢了这个菜单:
@include('/includes/category-menu-item', array('categories', $categories))
在includes/category-menu-item
内我有以下循环:
@if(is_array($categories))
<ul>
@foreach($categories as $key => $value)
<li>
@if(!is_numeric($key))
<p>{{$key}}</p>
@include('/admin/includes/category-menu-item', array('categories', $value))
@else
<button data-category-id="{{$value->id}}">{{$value->name}}</button>
@include('/admin/includes/category-menu-item', array('categories', $value->children))
@endif
</li>
@endforeach
</ul>
@endif
这显然仍然不完整,但我已经遇到模板永远不会越过第一层并打印出来的问题:
业务资源
业务资源
业务资源
业务资源
......等......如何让Laravel识别新的数组值?或者有更好的方法吗?
答案 0 :(得分:1)
您的UIViewControllerAnimatedTransitioning
语句不正确。传递给视图的数据需要是关联的数组,您已经使用数字键传递了数组。您必须从@include
更改为array('categories', $value)
:
array('categories' => $value)