groupedFor - grouping objects according to dates

落花浮王杯 提交于 2020-01-06 04:18:28

问题


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>

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>

How can i group all appointments according to their date?

I want the ouput:

02.09:
appointmentname1
Jerry Maier

appointmentname2
Esther Tannbaum

appointmentname3
Johnny Free
_____________________________________________
06.09:

appointmentname4
Otto Kringel

回答1:


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');
}

This can be used then for grouping {appointments.dayOfDatetime}



来源:https://stackoverflow.com/questions/32369572/groupedfor-grouping-objects-according-to-dates

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!