【问题标题】:How do you select a default radio button in Ember?如何在 Ember 中选择默认单选按钮?
【发布时间】:2016-07-29 13:26:20
【问题描述】:
{{input type="radio" name="customerFacing" value=report.customerFacing id="customerFacingYes" change=(action "customerFacingChange" "yes")}}<label for="customerFacingYes">Yes</label>

如果变量“report.customerFacing”为真或假,我正在尝试将单选按钮设置为选中状态。有什么我可以用 javascript 编写的东西来将其设置为选中吗?

谢谢

【问题讨论】:

标签: javascript ember.js


【解决方案1】:

您的代码将适用于复选框。

{{input type="checkbox" name="customerFacing"  checked=report.customerFacing value=report.customerFacing id="customerFacingYes" on-change=(action (mut report.customerFacingChange) checked)}} 
<label for="customerFacingYes">{{report.customerFacing}}</label>

但是对于单选按钮,你可以试试插件。(https://github.com/yapplabs/ember-radio-button)

ember install ember-radio-button

{{#radio-button value=report.customerFacing groupValue=report.customerFacing class="cpntr" changed=(action "customerFacingChange")}}
      <label for="customerFacingYes">{{report.customerFacing}}</label>
 {{/radio-button}}

在控制器或任何其他地方,

actions: {
 customerFacingChange(newValue){
  console.log('Changed value'+newValue); //you can do other stuff here.
 }
}

【讨论】:

    猜你喜欢
    • 2021-05-13
    • 2013-03-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-16
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 2019-10-01
    相关资源
    最近更新 更多