【问题标题】:How to pass value from jQuery menu to Play framework如何将值从 jQuery 菜单传递到 Play 框架
【发布时间】:2015-03-03 19:23:47
【问题描述】:

我最近开始使用游戏框架。我正在尝试将 jQuery 与我的模板一起使用,但我不知道如何从 jQuery 传递值来播放。这是我的控制器:

public static Result createProduct() {
    String usernameSes = session("username");
    String name = newProduct.bindFromRequest().get().name;
    String desc = newProduct.bindFromRequest().get().desc;
    Double price = newProduct.bindFromRequest().get().price;
    **String category = newProduct.bindFromRequest().get.category;**
    Product.create(name, desc, price);
    return ok(showProduct.render(usernameSes, name, desc, price));

这是我的 jQuery:

        <script>
            $(function() {
            $( "#category" ).selectmenu(); 
            });
         </script>
        <style>
            fieldset {
            border: 0;
            }
        label {
            display: block;
            margin: 30px 0 0 0;
        }
        select {
            width: 200px;
        }
        .overflow {
            height: 200px;
        }
         </style>

        <body>

        <div class="demo">

        <form action="#">

        <fieldset>
        <label for="category">Kategorija</label>
        <select name="category" id="cathegory">
            <option selected="selected">Vozila</option>
            <option>Nekretnine</option>
            <option>Mobilni uređaji</option>
            <option>Kompjuteri</option>
            <option>Tehnika</option>
            <option>Nakit i satovi</option>
            <option>Moj dom</option>
            <option>Biznis i industrija</option>
            <option>Životinje</option>
            <option>Odjeća i obuća</option>
            <option>Ostale kategorije</option>
        </select>


        </fieldset>

        </form>

提前感谢您的回答!

【问题讨论】:

    标签: java javascript jquery playframework


    【解决方案1】:

    您只需要将路由文件中的地址链接到控制器上的方法 (see here)。

    那么您表单中的action 应该使用该地址。使用 Play 模板,您甚至可以使用语法

    <form action="@routes.YourControllerClass.createProduct()">
    

    然后,当提交表单时,createProduct() 方法会处理它。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多