I have a control set up like this:
- Renders a view loaded async.
- Data for the view is also loaded asynchronously.
- Listens to route changes. One of the route handler displays a modal with the details of a model loaded in step 2.
The problem is that the user might get to a page that has a route that point to a model, that is not available at the moment the control is initialized so, obviously, the modal is not loaded.
can.Control({
init: function() {
can.view('file.ejs', {pages: app.Model.Page.findAll()}, function(frag){
// inject the fragment into DOM
});
},
'page/:id/comments route': function() {
// find the page in the list of models loaded, than display the modal
}
});
How to I trigger the distcher again or make the controller go over the routes after the view is rendered?
If you store the Deferred that findAll returns somewhere, you can use that in your route to tell when its loaded.
http://canjs.com/docs/can.when.html
Here is a example that stores the pages in the this.pages on the Control:
(not very nice to look at but easy to understand)