[英]Mustache Template for nested array
How can I loop through this using mustache? 如何使用胡须循环进行此操作? I have an outer array of numeric indexes.
我有一个数字索引的外部数组。 Or how to do something else and keep this structure?
或者如何做其他事情并保持这种结构?
I tried: 我试过了:
<ul>
{{#cars}}
<li> {{#.}} {{.}} {{/.}}</li>
{{/cars}}
</ul>
> Array(
> [cars] => Array
> (
> [0] => Array
> (
> [0] => Array
> (
> [id] => 343443
> [name] => Mazda
> )
>
> [1] =>
> (
> [id] => 45353
> [name] => Toyota
> )
> )
> [1] => Array
> (
> [0] => Array
> (
> [id] => 922424
> [name] => Camry
> )
> )
> )//end cars
> )
Try this template: 试试这个模板:
<ul>
{{#cars}}
{{#.}}
<li>{{id}} - {{name}}</li>
{{/.}}
{{/cars}}
</ul>
Or convert the array: 或转换数组:
array_walk( $array['cars'], function($i) use (&$cars) {
foreach( $i as $v ) $cars['cars'][] = $v;
});
, and use this simpler template: ,并使用以下更简单的模板:
<ul>
{{#cars}}
<li>{{id}} - {{name}}</li>
{{/cars}}
</ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.