我有一个表示目录的映射,它包含 Chapter
键和 List[Section]
值。现在我正在尝试在我的模板中循环遍历它:
<dl>
@table_of_contents.foreach((e) => {
<dt>
@e._1.title
</dt>
for(section <- e._2){
<dd>
@section.title
</dd>
}
})
</dl>
目前在<dl>
标签中没有任何输出。
我在模板的顶部添加了一个println(table_of_contents)
语句,以确保映射确实有数据,并打印出:
{models.Chapter@1=BeanList size[4] hasMoreRows[false] list[models.Section@1, models.Section@2, models.Section@3, models.Section@4], models.Chapter@2=BeanList size[0] hasMoreRows[false] list[]}
也许我需要使用命令式风格?
更新:
仍在处理这个问题……编译出现了变化,但没有输出。
<dl>
@table_of_contents.foreach{case(a, b) => {
<dt>
@a.title
</dt>
@displaySections(b)
}}
</dl>
...
@displaySections(sections: List[Section]) = {
@for(a_section <- sections) {
<dd>@a_section.title</li>
}
}
foreach
зҡ„иҝ”еӣһзұ»еһӢжҳҜUnit
еҗ—пјҹдҪ иҜ•иҝҮдҪҝз”Ёmap
еҗ—пјҹ - Garethfor()
语法而不是调用foreach()
方法,然后它就起作用了。 - wfbarksdale