2015-09-07 74 views
2

我已经定义一个变量错误未找到:值

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

而你的问题是什么? – rightfold

+0

@FatimaKhan很好的问题.. :-) –

回答

0

的原因,你的代码不起作用的是,虽然var a在一个块中定义,但该范围内完成你实际使用之前a

使用defining

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

还要检查这个答案:

Declare variable in a Play2 scala template