使用Play Framework从HTML打开新网页

时间:2016-07-28 23:06:05

标签: scala playframework-2.0

我正在尝试拥有一个网页,进行一些用户搜索输入,然后使用Play Framework将该输入传递到新页面。但是,我在做这件事时遇到了一些问题。我觉得这可能相当简单,但我无法让它发挥作用。

我的路线:

# Home page
GET     /                           controllers.Application.index
GET     /:search                    controllers.Application.getSearchResult(search)
GET     /push-notifications         controllers.Application.socket
GET     /assets/*file               controllers.Assets.versioned(path="/public/app", file: Asset)

控制器:

  def index = Action { request =>
    Ok(views.html.index.render)
  }

  def getSearchResult(search: String) = Action { request =>
    val databaseSupport = new InteractWithDatabase(comm, db)
    val put = Future {
      while (true) {
        val data = databaseSupport.getFromDatabase(search)
        if (data.nonEmpty) {
          comm.communicator ! data.head
        }
      }
    }
    Logger.info("Gotcha")
    Ok(views.html.singleElement.render)
  }

index.scala.html:

@()

<!DOCTYPE html>
<html>
    <body>

        <h3>A demonstration of how to access a Search field</h3>

            <input type="search" id="search" value="mySearch" placeholder="Search for something...">
            <button onclick="myFunction()">Try it</button>

        <p>Click the button to get the placeholder text of the search field.</p>

        <p id="demo"></p>

        <script>
            function myFunction() {
                var input = document.getElementById("search").value.toString();
                window.location = @routes.Application.getSearchResult(input);
            }
        </script>


    </body>
</html>

我觉得我在这里犯了一些很大的概念错误。任何和所有的帮助将不胜感激。

提前致谢。

0 个答案:

没有答案