Chih-Chao Lam
Chih-Chao Lam

Reputation: 514

Emberjs bug? Observer called when value is changed, but other bindings to same value is not updated

I have an observer to a value "App.selectedValue". I also have another Ember object that has a binding (App.someObj.appValueBinding) to App.selectedValue. However, when my observer is called, the binding of App.someObj is not updated.

This is illustrated in http://jsfiddle.net/Ur2Qj/8/

In the jsfiddle, you can see in the Chrome debugger or FireBug, that App.selectedValue and App.someObj.appValue have different values, even tho' the latter is bound to the former.

Seems like the binding should be updated when the observer is called. Is this expected behavior in Emberjs or is it a bug? Is there a work-around?

Thanks for looking at this!

Upvotes: 0

Views: 302

Answers (1)

Roy Daniels
Roy Daniels

Reputation: 6309

Take a look at this: http://jsfiddle.net/ud3323/GUHCD/ (in JavaScript; I don't like CoffeeScript... sorry).

The two main things you've got wrong here is not using get() and set() properly and in your observer you need to set App.someController.content after the end of the current runloop (which means after all the other bindings have taken place). You do this by using Ember.run.next(). You could also use Ember.run.sync() there as well.

Oh and you need to use jQuery 1.7.1. Version 1.5.2 is not compatible with Ember.

Upvotes: 2

Related Questions