scala模板中的地图不会打印元素

时间:2015-09-19 16:35:13

标签: scala playframework-2.0

我正在学习Play,我遇到了以下问题:我想在Scala模板中显示列表中的元素。从这个post开始,我看到我可以在列表中使用函数map但在我的情况下,为了显示属性的内容,它显示了:

@product.description
@product.name
@product.description
@product.name
@product.description
@product.name
@product.description
@product.name
@product.description 

Product.scala

package models

case class Product(ean : Long, name : String, description : String)

object Product {
  var products = Set(
    Product(5010255079763L, "Paperclips Large", "Large Plain Pack of 1000"),
    Product(5018206244666L, "Giant Paperclips", "Giant Plain 51mm 100 pack"),
    Product(5018306332812L, "Paperclip Giant Plain", "Giant Plain Pack of 10000"),
    Product(5018306312913L, "No Tear Paper Clip", "No Tear Extra Large Pack of 1000"),
    Product(5018206244611L, "Zebra Paperclips", "Zebra Length 28mm Assorted 150 Pack")
  )

  def findAll = products.toList.sortBy(_.ean)
}

这里我是如何显示元素的:

@(products : List[Product])(implicit lang : Lang)

@main(Messages("application.name")) {
<dl class="products">
  <!-- This is working -->
  <!-- @for(product <- products) { -->
  <!-- <dt>@product.name</dt> -->
  <!-- <dd>@product.description</dd> -->
  <!-- } -->
  @products.map(product =>
    <dt>@product.name</dt>
    <dd>@product.description</dd>)
</dl>
}

为什么for表达式正常工作而不是我想要的map

0 个答案:

没有答案