简体   繁体   English

模板中的java play框架访问HashMap

[英]java play framework access HashMap in template

I have a tag like this 我有这样的标签

   public class AcsTag {


         public static String getStyles(String paramter) {
             return hashMap<String, String>()

             }

         }
     }

I can access this tag in template (scala.html) like this 我可以像这样在模板(scala.html)中访问此标签

 @import com.twago.fms.shared.ui.AcsTag


 @AcsTag.getStyles(paramter)

getStyles method return a HasMap, I want to store that hashMap in a variable and then later get value from this hash map by key. getStyles方法返回一个HasMap,我想将该hashMap存储在一个变量中,然后再通过键从此哈希图中获取值。 I do want to iterate over map . 我确实想遍历地图。 I specifically want to access values by key. 我特别想通过键访问值。

following code i tried but always give error 以下代码我尝试过,但总是给错误

"map not defined" “未定义地图”

  map =@{AcsTag.getStyles(paratmeter))}
  @{map.get("themeColor")}

error "map not defined" 错误“未定义地图”

To declare a variable, you have to set at the top of your template: 要声明变量,必须在模板顶部设置:

@yourValue = @{yourExpression}

So, to declare a map value, you should do: 因此,要声明map值,您应该执行以下操作:

@map = @{AcsTag.getStyles(parameter)}

Then you'll be able to use yout map value anywhere in your template. 然后,您将可以在模板的任何位置使用map值。 Eg: 例如:

<div class="@map.get("themeColor")">...</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM