通过不同的路径渲染相同的视图/控制器

时间:2013-06-03 00:22:00

标签: ember.js

我的应用程序中有一个视图(和控制器),将“editingMode”布尔值设置为true更有意义,以便将其置于编辑模式。

编辑时,我想显示几个不同的模态(每个模式都在路由器下有我们的资源)。所以我在确定正确的方法时遇到了一些问题。

/category        # "normal" view
/category/edit   # category view/controller with the "editMode" set to true
/category/edit/subcategory  # needs to show the categoryController with editMode set to true and then subcategory index above it. 

所以路由器设置如下:

App.Router.map(function(){ 
  this.resource('category', function(){
    this.route('edit');
    this.resource('subcategory', function (){});
  });
});

显然,我无法在subcategory下创建edit嵌套资源。所以我认为我的两个选择是。

选项一

放置主控制器,处理CategoryCategoryIndexController的所有功能。但这需要两件事。

  1. 类别的编辑模式加载视图和控制器(这很容易)
  2. 我想要的每个模态必须首先加载索引视图,然后将自身加载到该视图中。这很烦人,看起来不像选项#2那么干净。
  3. 选项二

    将主控制器置于CategoryController下。这意味着:

    1. CategoryIndexController确实无能为力。
    2. 编辑模式仍会告诉CategoryController将其编辑模式设置为true
    3. 模态不会发生任何事情(除了告诉CategoryController它应该处于编辑模式。
    4. 对我来说,这似乎是更清晰的选择,但我无法看到它work。有什么想法吗?

      有没有更好的方法来做到这一点或更“正确”的方式?

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用CategoryIndexController代替CategoryController。默认情况下,CategoryController会重定向到CategoryIndexController,因为这是一种资源。

相关问题