groupedFor-根据日期对对象进行分组 [英] groupedFor - grouping objects according to dates
本文介绍了groupedFor-根据日期对对象进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码不会根据约会日期对我的约会进行分组.属性date是DateTime对象(时间戳).
The below code won't group my appointments according to the appointment-dates. The property date is a DateTime object (timestamp).
<f:groupedFor each="{appointments}" as="appointmentofdate" groupBy="date" groupKey="groupdate">
{groupdate}:
<br>
<f:for each="{appointmentofdate}" as="appointment">
{appointment.name} <br>
{appointment.contact}
</f:for>
<hr>
</f:groupedFor>
尝试将日期格式化为"d.m"格式也无法解决问题:
Trying to format the date to the form "d.m" also didn't solve the issue:
<f:groupedFor each="{appointments}" as="appointmentofdate" groupBy="{f:format.date(date: date, format: 'd.m')}" groupKey="groupdate">
{groupdate}:
<br>
<f:for each="{appointmentofdate}" as="appointment">
{appointment.name} <br>
{appointment.contact}
</f:for>
<hr>
</f:groupedFor>
我如何根据约会将所有约会分组?
我想要输出:
02.09:
appointmentname1
Jerry Maier
appointmentname2
Esther Tannbaum
appointmentname3
Johnny Free
_____________________________________________
06.09:
appointmentname4
Otto Kringel
推荐答案
您的模型中需要额外的吸气剂.重命名字段
You need an additional getter in your model. Rename the field
/**
* Get day of datetime
*
* @return int
*/
public function getDayOfDatetime()
{
return (int)$this->date->format('d');
}
然后可以将其用于分组{appointments.dayOfDatetime}
This can be used then for grouping {appointments.dayOfDatetime}
这篇关于groupedFor-根据日期对对象进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文