【问题标题】:Error not found: value a未找到错误:值 a
【发布时间】:2015-12-02 19:58:19
【问题描述】:

我已经定义了一个变量

@(mapCollectionCount: Map[String, String]) //values coming from controller
@{var a=0} 
<script type="text/javascript"> 
  var r=@mapCollectionCount.get("receipts"); 
  r=r.toLocaleString();
</script>
<div> @a<div> //gives me error not found: value a

【问题讨论】:

  • 你的问题是?
  • @FatimaKhan 好问题.. :-)

标签: javascript scala playframework


【解决方案1】:

您的代码不起作用的原因是,虽然var a 是在一个块中定义的,但该范围在您实际使用a 之前就结束了。

使用defining

@(mapCollectionCount: Map[String, String]) //values coming from controller
@defining(0) { a => 
 <script type="text/javascript"> 
  var r=@mapCollectionCount.get("receipts"); 
  r=r.toLocaleString();
 </script>
 <div> @a<div> //shouldn't give error
}

还要检查这个答案:

Declare variable in a Play2 scala template

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-04
    • 2018-05-14
    • 1970-01-01
    • 2013-09-21
    相关资源
    最近更新 更多