2012-05-27 5 views
1

ember 라디오를 클릭하면 아래와 같이 bindingChanged 함수를 사용하여 클릭 된 라디오를 관찰합니다. 그러나 라디오 버튼을 클릭하자마자 값은 관측되지 않고 따라서 bindingChanged 메소드를 치지 않습니다. 이것은 ember 0.9.8 버전에서 잘 작동했습니다. 그것은 최신 ember 버전과 작동하지 않습니다. 관찰자가 예상대로 작동하지 않는 이유는 무엇입니까?Ember js observer issue

//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})); 
    } 
}); 

핸들 바 스 니펫 (snippet) : 아래

{{ 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 여기