2015-09-07 178 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