Loop over java Map with scalate's mustache implementation
Can mustache loop over a java Map? My object:
Map<Integer, String> mapTest
Tried this in my mustache template:
{{#mapTest}}
{{.}}
{{/mapTest}}
That spits out a string representation (mapTest.toString()
) of the entire object but doesn't loop at all.
Update: In hunting through the source I'm getting closer but still not sure how to do it. https://github.com/scalate/scalate/blob/ec981338c067fcf37106fb5f3bdf2fa8c4e458ca/scalate-core/sr开发者_如何学运维c/main/scala/org/fusesource/scalate/mustache/Scope.scala#L124-125
See this answer on the mailing list...
http://groups.google.com/group/scalate/msg/100df004001d84f0
You could convert the Java Map to a Scala Map.
import scala.collection.JavaConverters._
val myScalaMap = myJavaMap.asScala.mapValues(_.asScala.toSet)
I wouldn't hack the template to accommodate a Java object.
精彩评论