Javascript 找不到错误:值a
我定义了一个变量Javascript 找不到错误:值a,javascript,scala,playframework,Javascript,Scala,Playframework,我定义了一个变量 @(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> //g
@(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
@(mapCollectionCount:Map[String,String])//来自控制器的值
@{var a=0}
var r=@mapCollectionCount.get(“收据”);
r=r.toLocaleString();
@a//给我找不到错误:值a
代码不起作用的原因是,虽然var a
是在块中定义的,但该范围在实际使用a
之前结束
使用定义:
@(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
}
@(mapCollectionCount:Map[String,String])//来自控制器的值
@定义(0){a=>
var r=@mapCollectionCount.get(“收据”);
r=r.toLocaleString();
@a/不应该给出错误
}
请检查以下答案:
你的问题是?@FatimaKhan好问题…-)