ember ラジオをクリックすると、以下の bindingChanged という名前の関数を使用して、クリックされたラジオを観察します。しかし、ラジオボタンがクリックされるとすぐに値が観察されないため、bindingChanged メソッドにヒットしません。これは、ember 0.9.8 バージョンで正常に機能していました。最新のemberバージョンでは動作しません。オブザーバーが期待どおりに機能しない理由は何ですか?
//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'));
}
});
ここに 元のフィドルがあり、下に別のフィドルがあります。フィドルの下にバグが表示されます。主な違いは、最新の残り火があり、別のフィドルを完全に壊していることです