未发现错误:值为a

Error not found: value a

本文关键字:值为 错误 未发现      更新时间:2023-09-26

我已经定义了一个变量

@(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

你的代码不工作的原因是,虽然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
}

也检查这个答案:

在Play2 scala模板中声明变量