将灰烬模型绑定到无线电场

时间:2015-11-02 16:03:01

标签: ember.js

我有一个简单的输入无线电,​​用于在活动和非活动之间切换。我无法弄清楚如何让Ember将其与模型联系起来。我的RAW html目前看起来像这样:

<fieldset class="checkboxes">

<label class="active" for="is_active">
  <input type="radio" id="is_active" name="status" value="1" checked="">
  <span>Active</span>
  <div class="input"></div>
</label>

<label class="sep">/</label>

<label class="inactive" for="inactive">
  <input type="radio" id="inactive" value="0" name="status">
  <span>Inactive</span>
  <div class="input"></div>
</label>

有没有人对如何使用Ember表单模型绑定有任何想法?

1 个答案:

答案 0 :(得分:2)

使标签动作,这样您就可以在控制器中使用它们。我希望这有帮助......

<fieldset>
    <label class="option-buttons" for="reason1" {{action "setDeclineReason" "Too Expensive" on="mouseDown"}}>
        <input name="decline-reason" id="reason1" value="Too Expensive" type="radio">
        <span>
            <div class="check"></div>
            Too expensive
        </span>
    </label>
    <label class="option-buttons" for="reason2" {{action "setDeclineReason" "Lack of Amenities" on="mouseDown"}}>
        <input name="decline-reason" id="reason2" value="Lack of Amenities" type="radio">
        <span>
            <div class="check"></div>
            Lack of amenities
        </span>
    </label>
</fieldset>

App.DeclineController = Ember.Controller.extend({
  declineReason: null,
  decline: function(){
         var update = this.store.update('request', {
                id: this.get('model').id,
                user_decline_reason: this.get('declineReason')
            });
         update.save();
  actions:{
     setDeclineReason: function(declineReason){
         this.set('declineReason', declineReason);
     }
   }
});