不同的Ember路由或在自己的上下文中显示两个复杂视图 [英] Different Ember Routes or Displaying Two Complex Views in their own context

查看:115
本文介绍了不同的Ember路由或在自己的上下文中显示两个复杂视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序有不同的相关问题。我有左边的项目列表影响了右边的一些项目(想Github问题),但这里是一个模型。





所有罚款,我点击第一项,对。但是,左侧的列表具有自己的路由需求,它是具有嵌套路由的项目的资源。例如,当我们点击创建新项目时,我们将显示一个新的表单(见左下角)





当我这样做时,即使它在另一个插座上,它覆盖了目前的在其他网点提供。在这种情况下,产品在右边。



如果我们可以为不同的部分选择不同的路由器,那将是理想的。我知道我可以调用渲染并创建一个新的视图/控制器,但这将需要我来处理我自己的状态(我创建一个新的项目,编辑它,查看索引等)。



我目前正在查询查询参数作为选项。



任何想法?

解决方案

可以注册一个不同的路由器并将其注入到控制器中。从ember的源代码:

  / ** 
@private

这创建一个容器使用默认的Ember命名约定。
它还配置容器:
....
*所有控制器接收路由器作为它们的目标和控制器
属性
* /

buildContainer:function(namespace){
var container = new Ember.Container();

//为了简洁起见删除了一些代码...
container.register('controller:basic',Ember.Controller,{instantiate:false});
container.register('controller:object',Ember.ObjectController,{instantiate:false});
container.register('controller:array',Ember.ArrayController,{instantiate:false});
container.register('route:basic',Ember.Route,{instantiate:false});

container.register('router:main',Ember.Router);

container.injection('controller','target','router:main');
container.injection('controller','namespace','application:main');

container.injection('route','router','router:main');

返回容器;
}

可以创建第二个路由器,在容器中注册并注入到某些控制器:

  App.Router = Ember.Router.extend(); 
App.Router.map函数(){...}

然后注册

  container.register('router:secondary',App.Router); 
container.injection('controller:list','target','router.secondary');


I have an app with different related concerns. I have a list of items on the left that affect some of the items on the right (think Github Issues), but here's a mockup

All fine, I click Item One and something happens on the right. However, the list on the left has its own routing requirements, it's a resource of items with nested routes. For example when we click on Create New Item we display a new form inline (see bottom left corner)

When I do that it, even if it's on a different outlet, it overrides what is currently rendered in other outlets. In this case the products on the right.

It would be ideal if we could just have different routers for different sections. I know I could just call render and create a new view/controller, but that would require me to handle my own states (am I creating a new item, editing it, looking at the index, etc).

I'm currently looking into query-params as an option.

Any ideas?

解决方案

It's possible to register a different router and inject this into controllers. From ember's source code:

/**
@private

This creates a container with the default Ember naming conventions.
It also configures the container:
....
* all controllers receive the router as their `target` and `controllers`
  properties
*/

buildContainer: function(namespace) {
    var container = new Ember.Container();

    // some code removed for brevity... 
    container.register('controller:basic', Ember.Controller, { instantiate: false });
    container.register('controller:object', Ember.ObjectController, { instantiate: false });
    container.register('controller:array', Ember.ArrayController, { instantiate: false });
    container.register('route:basic', Ember.Route, { instantiate: false });

    container.register('router:main',  Ember.Router);

    container.injection('controller', 'target', 'router:main');
    container.injection('controller', 'namespace', 'application:main');

    container.injection('route', 'router', 'router:main');

    return container;
}

A second router could be created, registered with the container and injected into certain controllers:

    App.Router = Ember.Router.extend();
    App.Router.map function () {...}

Then to register

    container.register('router:secondary',  App.Router);
    container.injection('controller:list', 'target', 'router.secondary');

这篇关于不同的Ember路由或在自己的上下文中显示两个复杂视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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