English 中文(简体)
我如何把一个检查箱装上游乐中的风ool! 框架
原标题:How do I bind a checkbox to a boolean in Play! framework

从事“游戏”工作的大约1米。 框架有一个称为“高原”的美术物品。 我如何把这一价值作为我的检查箱来显示? I ve Trial:-

<input id="gift_Taken" class="" type="checkbox" name="gift.Taken" value="true"  />
<input type="hidden" name="gift.Taken" value="false" />

以实例为依据 我从汽车产生的CRUD表格中看到,但当财产是真实的,即我所要达到的目的时,检查箱没有检查。

任何人都知道实现这一目标的正确方式?

最佳回答

页: 1 如果价值真的,则对检查箱的价值。

例如(假设观点中发送的物体称为gift,boolean值称为)。 Taken

<input id="gift_Taken" type="checkbox" name="gift.Taken" ${gift.Taken ?  checked :  }  />
问题回答

得到接受的答案实际上并不正确,因为它没有处理“未核对”案件。 处理这两起案件需要一个隐蔽的领域:

<input id="gift_Taken" type="checkbox" name="gift.Taken" ${gift.Taken ?  checked :  }  />
<input type="hidden" name="gift.Taken" value="false" />

Note that the placement seems to be important, so the hidden field must be after the checkbox.

编写这方面的习惯模板标签,很容易避免忘记隐藏的投入(将这种投入输入观点/标签/盒式框.html):

<input id="${_id}" type="checkbox" name="${_name}" value="true" #{if _checked} checked="checked" #{/if}>
<input type="hidden" name="${_name}" value="false">

Then call this template like this:

#{checkbox id: gift_Taken , name:  gift.Taken , checked: gift.Taken /}

另见关于游戏框架清单的相关讨论:https://groups.google.com/forum/?groups=#!topic/play-framework/HygQuYF3a8E

如果你能够使用 j,你可以使用:

$(document).ready(function() {
    $( ":checkbox" ).each(function() {
        var name = $(this).attr("name");
        if(typeof(name) != "undefined") {
            var checkboxString = "";
            checkboxString =  <input type="hidden" style="display:none;" name=" + name + " value="false" /> 
            $(this).after(checkboxString);
        }
    });
});




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签