【问题标题】:Emberjs Rendering other Templates within another templateEmberjs 在另一个模板中渲染其他模板
【发布时间】:2013-11-25 16:41:38
【问题描述】:

我想在模板“许可”的边栏中呈现模板“位置”。 我的代码是 emberjs.com 的渲染模板示例中显示的代码的副本,但“位置”模板要么根本不加载,要么仅重复加载“位置”模板,但未在“许可”中渲染原始 html模板。因此 location.hbs 会显示,但不在分配给它的侧边栏中。

这是一些代码:D

<!-- Right Sidebar (a small piece of the 'permit' template) START -->
    <div id="sidebar-wrapper" class="super-super-float-right-col">
      <div id="sidebar-wrapper" class="super-float-right-col">
        <div id="sidebar-wrapper" class="float-right-col">
          {{outlet location}}
        </div>
      </div>
    </div>
  <!-- Right Sidebar END -->


VpcYeoman.PermitRoute = Ember.Route.extend({
    renderTemplate: function() {
        this.render('location');
    }
});

路由器.js

VpcYeoman.Router.map(function () {
...
  this.resource('permit', { path: '/permit/:permit_id' });
...
});

http://emberjs.com/guides/routing/rendering-a-template/ 再次变得含糊不清,帮助不大。

emberjs 社区集合!

【问题讨论】:

    标签: templates ember.js routes rendering router


    【解决方案1】:

    您已经创建了一个命名插座,但没有告诉它渲染到该命名插座。您正在使用的代码是渲染location 模板,而不是默认模板(permit)。你会按照下面的方式做一些事情

    this.render('location', {   // the template to render
      into: 'permit',                // the route to render into
      outlet: 'location',              // the name of the outlet in the route's template
      //controller: 'blogPost'        // the controller to use for the template
    });
    

    【讨论】:

      【解决方案2】:

      感谢大佬的帮助!

      http://emberjs.com/guides/routing/rendering-a-template/ 与解决方案相比具有很大的误导性。

      PermitRoute 中写入的内容必须与 .hbs 文件中写入的内容相同,并加一个冒号。

      renderTemplate: function() {
          this.render({ render:'location'});
      }
      

      所以放入 HTML 的内容不会是 {{outlet location}},正如他们的网站声称的那样,它只会呈现“位置”而不是“许可”,但 {{render '位置'}} 将呈现模板中的模板。

      【讨论】:

      • 或者,您仍然可以使用您命名的插座并执行this.render();(按照惯例将呈现许可)和this.render('location', {outlet: 'location'}); 来呈现侧边栏。关键是如果你覆盖renderTemplate,你需要调用super,如果你仍然希望默认渲染发生,你需要调用this.render();。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-23
      • 2014-01-15
      相关资源
      最近更新 更多