MustachePHP-是否可以迭代两个数组
我有一个场景,在这个场景中,我想在汇总表中显示各个员工在给定的一周中工作的小时数。样本数据的结构如下所示MustachePHP-是否可以迭代两个数组,php,mustache,mustache.php,Php,Mustache,Mustache.php,我有一个场景,在这个场景中,我想在汇总表中显示各个员工在给定的一周中工作的小时数。样本数据的结构如下所示 $days = {'Mon','Tues','Wed','Thurs','Fri','Sat'}; // list of working days $employees = { // the hours for each employee and day {'Mon'=>'4h','Fri'=>'8h'}; {'Mon'=>'4h','Tues'=>
$days = {'Mon','Tues','Wed','Thurs','Fri','Sat'}; // list of working days
$employees = { // the hours for each employee and day
{'Mon'=>'4h','Fri'=>'8h'};
{'Mon'=>'4h','Tues'=>'8h','Thurs'=>'8h','Sat'=>'2h'}
};
我使用这个小胡子模板来构建“表”和第一行“日”列标题
<table width="100%" class=" table-1">
// display all the days
<thead>
<tr>
{{# days }}
<th>{{ . }}</th>
{{/ days }}
</tr>
</thead>
// sudo logic??
{{#employee}} // list all the employee's
<tr>
{{# days }} // iterate all the days
{{#employee.day==.}} // if employee this day
<td>{{employee.hours}}</td>
{{/}}
else
<td></td>// empty cell
{{/ days }}
</tr>
{{/employee}}
</table>
//显示所有日期
{{{天}
{{ . }}
{{/天}
//sudo逻辑??
{{{#employee}}//列出所有员工的
{{{天}}//迭代所有的天
{{{#employee.day==.}///如果员工当天
{{employee.hours}
{{/}}
其他的
//空电池
{{/天}
{{/雇员}
我想知道是否可以使用匹配逻辑来确保“employee”数组的每个“hours”字段都显示在正确的“day”列下。我很感激重新构造数组中的数据可以使模板暂时变得简单,让我们假设我做不到。您确实正确地编写了它。问题是什么?我还没有真正实现解决方案,因为我预计尝试一些不起作用的东西会浪费大量时间。我是否不需要重新构造“employees”数组,将“day”和“hour”键包含到可以正确识别正确值的小胡子中?