How To Use Scala And Html Code Inside Single Block
why option html element is not binded inside select in case 1? Case 1: not work @base{
Solution 1:
The code block @{...}
is a closure that has an inferred return type from the last statement.
In the first case the return type is inferred to be Unit
since the println(...)
returns Unit
In the second block the html is returned.
Solution 2:
I can't speak to the first question directly, but assuming that @korefn and @om-nom-nom are correct; that the block is a closure and is interpreting the return as a void.
In response to your update, I would try:
@for(i <- 1 to 10) {
<option value="@i">@i</option>
}
which is how I've used it in the past. I've also found it helpful to use a nested @if block to handle the selected option differently so that it is selected on loading the document.
Post a Comment for "How To Use Scala And Html Code Inside Single Block"