Is there a simpler way of doing this?
$(document).ready(function () {
var jsArray = []
@if(scalaList != null) {
@for(id <- scalaList) {
jsArray.push('@id');
}
}
...
}
Is there a simpler way of doing this?
$(document).ready(function () {
var jsArray = []
@if(scalaList != null) {
@for(id <- scalaList) {
jsArray.push('@id');
}
}
...
}
It's as simple as the following:
You can also do that within a template:
You can use mkString for this.
You should omit this if statement in view. Instead of this, check null in controller and put empty list to view, so this code can be more simpler in view
You don't need this quotes ' ' around id. In javascript 1 == '1' is true
I think every answer are good but still not safe because every answers don't care about value which including ' or ". Fortunately play framework support json, so you should use json to convert to javascript array.
Have you tried something like:
or you can use a literal like
Also the
if
check is not required.For
comprehensions are smart like that