When a create a view from an object, it seems that when I change a property in the object, the view’s property also changes. If I change the property in the view, the change is not reflected in the object. I thought two-way bindings were the default behavior. Am I missing something?
WidgetClass = Ember.Object.extend
address: 'widget address'
create_view: ->
# console.log this.name
view = Ember.View.create
someobj: this
addressBinding: 'someobj.address'
template: Ember.Handlebars.compile '{{address}}'
return view
TextWidget = WidgetClass.create()
view = TextWidget.create_view()
view.append()
view.set 'address', 'new new address'
console.log (view.get 'address')
console.log (TextWidget.get 'address') # I am expecting this output to be 'new new address'
When applying bindings and then testing them immediately, you need to force the Ember run loop to catch up. Try adding
Ember.run.sync()beforeview.set 'address', 'new new address'. YoursetTimeout()call should no longer be needed.