[这是关于新的 1.0.0-pre.4+ 路由器。]
我想从 Ember Route 的model
方法返回一条需要异步回调才能加载的记录,例如因为它需要我们加载多个(嵌套)模型。最好的方法是什么?
下面是一个假设的博客应用程序的示例代码,它说明了这个问题:
App.Router.map ->
@resource 'filteredArticles', path: '/:filter'
App.FilteredArticlesRoute = Ember.Route.extend
model: (params) ->
blog = App.Blog.find(1) # get the user's Blog singleton
property = switch params.filter
when 'published' then 'publishedArticles'
when 'draft' then 'drafts'
when 'all' then 'articles'
# Return the list of articles from the `blog` record.
# But `blog` hasn't necessarily finished loading :(
blog.get(property)