2012-05-27 54 views
1

點擊ember無線電時,使用下面的名爲bindingChanged的函數觀察點擊的無線電。但是,一旦單選按鈕被點擊的值不會被觀察到,因此不會觸及bindingChanged方法。這用於使用燼0.9.8版本正常工作。它不適用於最新的ember版本。任何想法爲什麼觀察員不按預期工作?Ember js觀察者問題

//valueBinding snippet 
App.showSampleController = Ember.Object.create({ 
    content : App.CreateSampleModel.create() 
}); 

App.CreateSampleModel= Ember.Object.extend({ 
    id :'' 
}); 

//View Template --> 
App.sampleView = Em.View.extend({ 
    click:function(){ 
     App.showSampleController.set('content',App.CreateSampleModel.create({id:1})); 
    } 
}); 

車把片段:

{{ view Ember.RadioButton group="default" name="sampleRadio" option=content.id valueBinding="App.showSampleController.content.id" }} 

下面是單選按鈕的代碼

Ember.RadioButton = Ember.View.extend({ 
    title: null, 
    checked: false, 
    group: "radio_button", 
    disabled: false, 
    customId:"open", 

    classNames: ['ember-radio-button'], 

    defaultTemplate: Ember.Handlebars.compile('<input type="radio" {{ bindAttr disabled="disabled" name="group" value="option" checked="checked" id="customId" }} />{{title}}'), 

    bindingChanged: function(){ 
     if(this.get("option") == get(this, 'value')){ 
      this.set("checked", true); 
      //invoking click when ember radio is accessed/checked/clicked!! 
      this.$('input:radio').click(); 
     } 
    }.observes("value"), 

    change: function() { 
     Ember.run.once(this, this._updateElementValue); 
    }, 

    _updateElementValue: function() { 
     var input = this.$('input:radio'); 
     set(this, 'value', input.attr('value')); 
    } 
}); 

這裏是一個original fiddle以下是另一個小提琴,你可以看到在小提琴中的錯誤。主要的區別是它擁有最新的餘燼和它完全打破another fiddle

回答

1

問題與模板視圖環境。你應該有你的模板像

<label><input type="radio" {{ bindAttr disabled="view.disabled" name="view.group" value="view.option" checked="view.checked"}} />{{view.title}}</label> 

Here是工作版本。 Refer here