How to dynamically update the Ember.Route model?

I have a route like this:

App.PeopleRoute = Ember.Route.extend({ model: function() { return App.Persons.find(personId); } }); 

where personId loads asynchronously and is a regular JavaScript variable outside of Ember. Now that the route is displayed, it gets the current PersonId and displays the correct data. But when I change the value of personId, it does not update the view.

So my question is, how can I update this route to find entries with a new personId?

+6
source share
1 answer

This is because the model hook only executes when entering through the URL for routes with dynamic segments. Read more about it here .

The easiest solution for this is to use transitionTo .

 App.PeopleRoute = Ember.Route.extend({ model: function(params) { return App.Persons.find(params.personId); }, actions: { personChanged: function(person){ this.transitionTo("people", person); } } }); App.PeopleController = Em.Controller.extend({ observeID: function(){ this.send("personChanged"); }.observes("model.id"); }); 
+2
source

Source: https://habr.com/ru/post/950954/


All Articles