Typo3 流体中的类型3嵌套数组
我正在将一个嵌套数组传递给流体模板,现在希望对它们进行迭代 唉,每一个的第二个只显示超级数组的键 数组(在伪代码中): 以及我的模板中的代码:Typo3 流体中的类型3嵌套数组,typo3,fluid,Typo3,Fluid,我正在将一个嵌套数组传递给流体模板,现在希望对它们进行迭代 唉,每一个的第二个只显示超级数组的键 数组(在伪代码中): 以及我的模板中的代码: <f:for each="{myArray}" as="topItem" iteration="it1" key="key"> <h4>{key}</h4> <f:for each="{topItem}" as="subItem" iteration="it2"> {sub
<f:for each="{myArray}" as="topItem" iteration="it1" key="key">
<h4>{key}</h4>
<f:for each="{topItem}" as="subItem" iteration="it2">
{subItem.title}<br />
{subItem.content}
</f:for>
</f:for>
{key}
{subItem.title}
{subItem.content}
我做错了什么?作为答案的评论摘要以及提到的
f:for
和f:groupedFor
查看帮助程序的示例f:for
基本上适用于任何类型的数组,并允许在每一层嵌套数据上进行迭代-f:group
适用于将平面数据结构转换为嵌套数据集
f:for
输入数组是二维的,如下所示
$this->view->assign('nestedItems', [
'2016' => [
['title' => '1st Title', 'content' => '1st Content'],
['title' => '2nd Title', 'content' => '2nd Content'],
],
'2015' => [
['title' => '3rd Title', 'content' => '3rd Content'],
['title' => '4th Title', 'content' => '4th Content'],
],
]);
迭代嵌套数据集的流体模板如下所示
<f:for each="{nestedItems}" as="items" key="currentYear">
<h2>{currentYear}</h2>
<f:for each="{items}" as="item">
<h3>{item.title}</h3>
<p>{item.content}</p>
</f:for>
</f:for>
<f:groupedFor each="{flatItems}" as="items" groupBy="year" groupKey="currentYear">
<h2>{currentYear}</h2>
<f:for each="{items}" as="item">
<h3>{item.title}</h3>
<p>{item.content}</p>
</f:for>
</f:groupedFor>
迭代嵌套数据集的流体模板如下所示
<f:for each="{nestedItems}" as="items" key="currentYear">
<h2>{currentYear}</h2>
<f:for each="{items}" as="item">
<h3>{item.title}</h3>
<p>{item.content}</p>
</f:for>
</f:for>
<f:groupedFor each="{flatItems}" as="items" groupBy="year" groupKey="currentYear">
<h2>{currentYear}</h2>
<f:for each="{items}" as="item">
<h3>{item.title}</h3>
<p>{item.content}</p>
</f:for>
</f:groupedFor>
{currentYear}
{item.title}
{item.content}
两种方案的输出
两种情况下的输出相同
<h2>2016</h2>
<h3>1st Title</h3>
<p>1st Content</p>
<h3>2nd Title</h3>
<p>2nd Content</p>
<h2>2015</h2>
<h3>3rd Title</h3>
<p>3rd Content</p>
<h3>4th Title</h3>
<p>4th Content</p>
2016
第一名
第一内容
第二名
第二内容
2015
第三名
第三内容
第四名
第四内容
看起来肯定没有错-你能给我们看一下{myArray}
的输出(屏幕截图)吗?我设法让它工作了-但是谢谢你的回复!请接受/关闭该问题-并可能添加用于使其正常工作的最终代码;)不过,贴在这里的液体实际上应该是有效的。