I need to feed a javascript element with values from a Map as shown below.
My render feeds the HTML document with:
${GetFileVersion} "$UserDir\thirdParty.exe" $CurrentVersionString
StrCpy $CurrentVersion $CurrentVersionString
DetailPrint "The Current version is: $CurrentVersion"
The JS looks like this:
@(morrisDonut: Map[String, Integer])
The script stops because it dont can't find/can't use activity and steps even though its the correct types.
SOLUTION:
$.getScript('https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.2/raphael-min.js',function(){
$.getScript('https://cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js',function(){
var donutData = [];
@for((activity, steps) <- morrisDonut) {
donutData.push({label: activity, value: steps});
}
Morris.Donut({
element: 'user_activity-donut',
data: donutData
});
});
});
Adding " ' " and " @ " symbols seemed to work just fine
答案 0 :(得分:3)
根据您的语法,我认为(我在这里推断很多)您正在使用Play框架 - 即Twirl templates。如果是这种情况,那么您只是在加载@
数组的关键点缺少一些参数运算符(donutData
):
@for((activity, steps) <- morrisDonut) {
donutData.push({label: @activity, value: @steps});
}
将Twirl指令与另一种语言混杂起来可能很棘手,因为在设计上,没有明确的&#34;这是我的Twirl代码的结束&#34;标记 - 它都是推断的。所以在你的情况下,第一行和第三行被Twirl正确解释,但第二行看起来只是一些静态内容 - 它将按原样插入。
通过添加魔术@
符号,可以检测到必要的替换。