0
我正在嘗試玩'框架教程,它可以在'localhost:9000'中看到。Playframework不顯示錶單標籤:斯卡拉
正如它所說的,我編輯了文件並進行編譯,但沒有顯示出我期望的結果。 關注是我所做的。在控制檯
- 化妝遊戲項目(命令:打新的Alpha)
- 然後我跑了(移動「阿爾法」目錄和打運行)
- 在/阿爾法/應用程序將名爲「模型」的文件夾/控制器。
編輯Application.scala
package controllers import play.api._ import play.api.mvc._ import play.api.data._ import play.api.data.Forms._ import models.Task object Application extends Controller { val taskForm = Form("label" -> nonEmptyText) def index = Action { //Ok(views.html.index("Your new application is ready.")) //Ok("Let's Play!") Redirect(routes.Application.tasks) } def tasks = Action { Ok(views.html.index(Task.all(), taskForm)) } def newTask = Action { implicit request => taskForm.bindFromRequest.fold( errors => BadRequest(views.html.index(Task.all(), errors)), label => { Task.create(label) Redirect(routes.Application.tasks) } ) } def deleteTask(id: Long) = TODO }
使/alpha/controllers/models/Task.scala
package models case class Task(id: Long, label: String) object Task { def all(): List[Task] = Nil def create(label: String) {} def delete(id: Long){} }
最後我編輯/阿爾法/ conf目錄/路線
# Routes # This file defines all application routes (Higher priority routes first) # ~~~~ # Home page GET / controllers.Application.index # Map static resources from the /public folder to the /assets URL path GET /assets/*file controllers.Assets.at(path="/public", file) #Tasks GET /tasks controllers.Application.tasks POST /tasks controllers.Application.newTask POST /tasks/:id/delete controllers.Application.deleteTask(id: Long)
然後我跑了。我期望一個表單區域和一個按鈕「創建」。按鈕是好的,而窗體沒有。我收到了一些消息,而不是表單。下面是那個消息。
BaseScalaTemplate([email protected]) (taskForm( 「標籤」))
我不能跟蹤這一點,因爲這是不是一個錯誤。有沒有任何線索來解決這個錯誤?如果你給出的解決方案或線索,將非常感激:D
==========感謝分享我的問題================= =====
[index.scala.html]
> @* Comment : @(message: String) *@ @(task: List[Task], taskForm:
> Form[String]) @import helper._
>
> @main("Todo list") {
>
> <h1>@task.size task(s)</h1>
>
> <ul>
> @task.map { task =>
> <li>
> @task.label
>
> @form(routes.Application.deleteTask(task.id)) {
> <input type="submit" value="Delete">
> }
> </li>
> } </ul>
>
> <h2>Add a new task</h2>
>
> @form(routes.Application.newTask) {
> @inputText (taskForm("label"))
> <input type="submit" value="Create"> } }
請,包括你的索引。 scala.html – vitalii
你可以在你的視圖模板中使用表單嗎?(我相信它是index.scala.html) 注意:模型應該直接位於app /文件夾中,而不是控制器/ – psisoyev
@vitalii, britva我編輯了我的帖子,以便您現在可以看到index.scala.html考慮表達正常的按鈕,我認爲魔術關鍵字'@'沒有問題。 –