scala-template

How to convert scala list to javascript array?

北城余情 提交于 2019-12-04 02:55:30
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: import play.api.libs.json.Json val jsArr: JsValue = Json.toJson(scalaList) You can also do that within a template: @(list: List[Any]) @import play.api.libs.json.Json <script type="text/javascript"> $(document).ready(function () { var jsArr = @Json.toJson(list); console.log(jsArr); }); </script> You can use mkString for this. $(document).ready(function () { var jsArray = @if(scalaList != null) { [

How to prefill a dropdown using scala template and play framework

爱⌒轻易说出口 提交于 2019-12-03 21:53:44
I am using scala template and Play 2.0 framework for my project. Let's say I have a user form with fields like name (textfield), age (dropdown). While creating the user I filled name as dave and selected age as 25. Now on my edit screen, I want my values to be prefilled, i know how to do it with textfield (i.e. set value as userForm('name')) but what about the dropdown? how to do it. Thanks Shawn Downs and biesior. Well, we can use @select scala helper class to show the pre-filled result. like. @select(userForm("age"),models.Age.values().toList.map(v => (v.getDisplayName(), v.getDisplayName())

How to print @ symbol in HTML with play framework (scala)

自作多情 提交于 2019-12-03 13:46:44
I am new to Scala and play 2.1 and I come from a PHP background. I am not able to print the @ symbol in HTML. I am getting the following error: not found: value Hotmail Here is my code: myname<label>@Hotmail.com</label> Please let me know how I can print the @ symbol. Thanks in advance. Double it: myname<label>@@Hotmail.com</label> It's called escape syntax. Other rules for play template framework can be found here You can also write HTML Entity code &#64 for printing @ symbol in your view file. 来源: https://stackoverflow.com/questions/19157571/how-to-print-symbol-in-html-with-play-framework

Is it possible to prettify scala templates using play framework 2?

空扰寡人 提交于 2019-12-03 04:22:49
问题 Using Play Framework 2 I've noticed the rendered Scala HTML templates don't like indented @if or @for . So, for example, something like that: <ul> @for(test <- tests) { <li>@test.name</li> } </ul> Will have extra unneeded spaces. To fix it, I need to do something like that: <ul> @for(test <- tests) { <li>@test.name</li> } </ul> Which will get messy with additional @defining or other statements. So, is there a way to prettify/beautify Scala templates rendering in order to get rid of extra

Is it possible to prettify scala templates using play framework 2?

旧街凉风 提交于 2019-12-02 17:38:00
Using Play Framework 2 I've noticed the rendered Scala HTML templates don't like indented @if or @for . So, for example, something like that: <ul> @for(test <- tests) { <li>@test.name</li> } </ul> Will have extra unneeded spaces. To fix it, I need to do something like that: <ul> @for(test <- tests) { <li>@test.name</li> } </ul> Which will get messy with additional @defining or other statements. So, is there a way to prettify/beautify Scala templates rendering in order to get rid of extra white spaces? UPDATE: Reading this thread I've noticed extra spaces and line breaks are added as well