问题描述
这是应用程序我正在使用的游戏!框架有一个名为礼物用布尔属性的对象,称为服用。如何显示该值的状态,在我看来,一个复选框?我试过: -
An app I'm working on using the Play! Framework has an object called gift with a boolean property, called Taken. How do I show the state of this value as a checkbox on my view? I've tried :-
<input id="gift_Taken" class="" type="checkbox" name="gift.Taken" value="true" />
<input type="hidden" name="gift.Taken" value="false" />
根据我从自动生成的CRUD的形式看到的例子,但该复选框没有被选中时,属性为True,这就是我的目标。
based on examples I've seen from the autogenerated CRUD forms, but the checkbox is not checked when the property is True, which is what I'm aiming for.
任何人都知道正确的方式来实现这一目标?
Anyone know the correct way to achieve this?
推荐答案
您只需要设置对复选框检查
值,如果该值是真实的。
You just need to set the checked
value against the checkbox, if the value is true.
例如(假设从视图发送的对象被称为礼品
和布尔值称为摘自
。
for example (assuming the object sent in from the view is called gift
, and the boolean value is called Taken
.
<input id="gift_Taken" type="checkbox" name="gift.Taken" ${gift.Taken ? 'checked':''} />
这篇关于我如何在播放一个复选框绑定到一个布尔值!骨架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!