在应用的每种状态下获取数据的最佳方法 [英] Best approach to fetch data in every state of app

查看:44
本文介绍了在应用的每种状态下获取数据的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经发现了这个 jsFiddle ,我现在想知道最好的显示方法是使用来自Ember.js的新v2路由器,在 IndexRoute match('/contributor/:contributor_id')的所有子路由中的贡献者列表.

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.

我遇到的问题是

App.IndexRoute = Ember.Route.extend({
    model: function() {
        return App.Contributor.find();
    }
});​

仅在指定的/路由上获取数据.

is only fetching the data on the specified / route.

直接导航到/#/contributor/[some_id] 时,不会加载 IndexRoute 的数据,用户首先必须导航到/查看参与者列表.

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.

我遇到的唯一可能的解决方案是在 application 模板中调用一个 ContributorsView .同时,我不知道如何用数据填充此视图,因为视图没有路由具有的 model 属性.

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.

推荐答案

我对新的路由器实现尚不满意,但是从设计的角度来看,我将对路由使用不同的结构,例如通过添加可从索引访问的贡献者路线,并且可能直接重定向到贡献者.然后,您将始终显示贡献者,并且在其中一个上单击时,您可以看到详细信息.一种主/明细块.

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.

这是路由器映射:

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');
    });
  });
});

这就是我要做的: http://jsfiddle.net/JLHuG/21/对您有用吗?

Here is what I would do: http://jsfiddle.net/JLHuG/21/ does it work for you ?

这篇关于在应用的每种状态下获取数据的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆