I get some data with $ .getJSON that I want to bind asynchronously to the controller context. I came up with this on my route - it works, but I'm not happy with this:
setupController: function(controller, model) { this._super(controller, model); Em.RSVP.Promise.cast(Em.$.getJSON((this.get('ENV.apiBaseURL')) + "/users/current/live_matchday_stats")).then((function(_this) { return function(s) { return _this.controller.set('matchdayStats', Em.Object.create(s)); }; }
Then in my template, I can, for example, use:
Foo: {{matchdayStats.foo}}
And everything works fine. Is there a better way to write this (possibly without promises and creating Em.Object). I know this automatically works if I embed Em. $. GetJSON in the hook of the model.
Matic jurglič
source share