问题
I've discovered this jsFiddle and I'm now wondering what the best approach would be to display the list of contributors both in the IndexRoute
and in all Subroutes of match('/contributor/:contributor_id')
with the new v2 Router from Ember.js.
The problem I'm experiencing is that
App.IndexRoute = Ember.Route.extend({
model: function() {
return App.Contributor.find();
}
});
is only fetching the data on the specified /
route.
When directly navigating to /#/contributor/[some_id]
the data for the IndexRoute
doesn't get loaded and the user would first have to navigate to /
to see the list of contributors.
The only possible solution I've come to is to have a ContributorsView
which gets called called in the application
template. Meanwhile I don't know how to populate this view with data, as a view doesn't have the model
property which the route has.
回答1:
I'm not yet confortable with the new router implementation, but from a design point of view, I would use a different structure for the routes, for example by adding a contributors route, accessible from the index, and perhaps directly redirect to contributors. Then you have always the contributors displayed, and when clicking on one of them you could see the details. A kind of master/detail blocks.
Here the router map:
App.Router.map(function(match){
match('/').to('home');
match('/about').to('about');
match('/contributors').to('contributors', function(match){
match('/').to('contributorsIndex');
match('/:contributor_id').to('contributor', function(match){
match('/').to('contributorIndex');
match('/details').to('contributorDetail');
match('/repos').to('contributorRepos');
});
});
});
Here is what I would do: http://jsfiddle.net/JLHuG/21/ does it work for you ?
来源:https://stackoverflow.com/questions/14125456/best-approach-to-fetch-data-in-every-state-of-app