【问题标题】:define multiple layouts emberjs定义多个布局 emberjs
【发布时间】:2014-03-02 22:44:32
【问题描述】:

我正在构建一个 emberjs 应用程序我想要有两个不同的布局,例如应用程序模板和另一个模板,我不希望我的所有视图都在应用程序模板中呈现,就像在 rails 中你可以指定有多个不同控制器的布局

【问题讨论】:

标签: javascript ruby-on-rails ember.js


【解决方案1】:

其实很简单,只要指定要渲染的模板:

App.ApplicationRoute = Ember.Route.extend({
  renderTemplate: function() {
    if (expression) {
      this.render('application');
    } else {
      this.render('site');
    }
  }
});

通过http://emberjs.com/guides/routing/rendering-a-template/

【讨论】:

    【解决方案2】:

    这是我从 emberjs 论坛得到的答案

    使用“layoutName”属性为两个布局创建两个视图:

      App.MainLayoutView = Ember.View.extend({ layoutName: 'layout/main', });
    

    和:

      App.SecondaryLayoutView = Ember.View.extend({
      layoutName: 'layout/secondary',
     });
    

    为布局创建两个模板,分别称为“layout/main”和“layout/secondary”。

    确保您的视图扩展了这些布局视图。例如,成像以下路由配置:

     App.Router.map(function() {
     this.resource('users', function() { this.route('new'); 
    this.route('login'); });
    

    });

    如果您希望所有用户路由都使用 MainLayout 并登录使用 Secondary 布局,请创建两个视图:

     App.ProjectsView = App.MainLayoutView.extend();
    

     App.LoginView = App.SecondaryLayoutView.extend();
    

    不需要为“projects/new”创建视图,因为它是项目的嵌套路由,因此继承了项目的布局。

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多