【问题标题】:does emberjs have an equivalent to rails `yield :something`?emberjs 是否具有与 rails `yield :something` 等价的功能?
【发布时间】:2013-04-16 15:23:39
【问题描述】:

在 Rails 中,您可以执行以下操作:

application.html.erb:

<h1><%= yield :title %></h1>
<%= yield %>

someother_template.html.erb:

content_for :title { 'Some Title' }

other stuffz

有没有办法使用 emberjs 来做这种事情?

【问题讨论】:

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


    【解决方案1】:

    有没有办法使用 emberjs 来做这种事情?

    如果你想要 yield-as-in-layouts 那么是的,你可以使用把手 {{yield}} helper 来包装视图

    AViewWithLayout = Ember.View.extend({
      layout: Ember.Handlebars.compile("<div class='my-decorative-class'>{{yield}}</div>")
      template: Ember.Handlebars.compile("I got wrapped"),
    });
    

    Ember.Handlebars.helpers#yield

    如果您希望将 yield-as-in-content-for 用作替代,则没有直接并行的 AFAIK。不确定 content-for 模式在把手模板的上下文中是否真的有意义,因为 content_for 是关于从模板内进行分配。在 ember 中,在应用程序模板中设置类似 {{title}} 的首选方法是将其绑定到应用程序控制器的属性。

    【讨论】:

    • 感谢您的解释。我有一种感觉,没有直接的等价物。我目前正在按照您建议的方式通过在应用程序模板中设置值来执行此操作。
    猜你喜欢
    • 1970-01-01
    • 2010-10-03
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    • 2012-09-19
    • 1970-01-01
    • 2011-02-28
    • 2011-12-02
    相关资源
    最近更新 更多