groupedFor - 根据日期对对象进行分组

时间:2015-09-03 07:34:04

标签: php typo3 fluid

以下代码不会根据约会日期对我的约会进行分组。属性日期是DateTime对象(时间戳)。

<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>

尝试将日期格式化为表格&#34; d.m&#34;也没有解决这个问题:

<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>

如何根据日期对所有约会进行分组?

我想要ouput:

02.09:
appointmentname1
Jerry Maier

appointmentname2
Esther Tannbaum

appointmentname3
Johnny Free
_____________________________________________
06.09:

appointmentname4
Otto Kringel

1 个答案:

答案 0 :(得分:1)

您的模型中需要额外的吸气剂。重命名字段

function buildTree(list) {
    // create a hash for the array. 
    // Start with a "root" entry for linking nodes with parentid = 0:
    var hash = { '0': { child: [] } };
    list.forEach( obj => hash[obj.s_gid] = Object.assign(obj, { child: [] }) );
    
    // move items into the appropriate child array
    list.forEach( obj => hash[obj.parent_id].child.push(obj) );
    
    // return the child array in the root element:
    return hash['0'].child;
}

//  Sample data
var vm = {};
vm.scholasticlist = [{
    "s_gid": "10",
    "m_s_p_id": "1",
    "subject_group_name": "Foundation of Information Technology",
    "parent_id": "0",
    "sname": ""
}, {
    "s_gid": "11",
    "m_s_p_id": "2",
    "subject_group_name": "Life Skills",
    "parent_id": "0",
    "sname": ""
}, {
    "s_gid": "15",
    "m_s_p_id": "2",
    "subject_group_name": "Thinking Skills",
    "parent_id": "11",
    "sname": "Th.sk"
}, {
    "s_gid": "15",
    "m_s_p_id": "2",
    "subject_group_name": "Thinking Skills",
    "parent_id": "11",
    "sname": "Th.sk"
}];

// Transform to tree
vm.scholasticlist = buildTree(vm.scholasticlist);

// Output result
console.log(vm.scholasticlist);

然后可以将其用于分组/** * Get day of datetime * * @return int */ public function getDayOfDatetime() { return (int)$this->date->format('d'); }