【问题标题】:Ember: How do I find handlebars partial in the directory?Ember:如何在目录中找到部分车把?
【发布时间】:2013-01-25 07:00:18
【问题描述】:

我正在使用 Ember.js(在 Rails 应用程序中)并在显示表单时得到了重点。我使用了“部分”车把标签,如下所示:

{{partial "entity_edit_fields"}}

Ember 尝试从 _entity_edit_fields.hbs 文件中检索模板。但是,我已将所有与实体相关的模板放入单独的目录中。现在,我想告诉 Ember 关注 entity/_edit_fields.hbs。我怎样才能做到这一点?

【问题讨论】:

    标签: ember.js


    【解决方案1】:

    要包含模板entity/_edit_fields.hbs 作为部分使用:

    {{partial "entity/edit_fields"}}
    

    如果您再次遇到类似问题,请尝试查看 ember 测试套件。几乎总会有一个例子可以帮助回答你的问题。我也不确定部分工作的效果,所以在回答之前我先看看handlebars_test.js

    test("should render other slash-separated templates using the {{partial}} helper", function() {
      Ember.TEMPLATES["child/_subTemplate"] = Ember.Handlebars.compile("sub-template");
    
      view = Ember.View.create({
        template: Ember.Handlebars.compile('This {{partial "child/subTemplate"}} is pretty great.')
      });
    
      Ember.run(function() {
        view.appendTo('#qunit-fixture');
      });
    
      equal(Ember.$.trim(view.$().text()), "This sub-template is pretty great.");
    });
    

    【讨论】:

    • 谢谢,伙计。像魅力一样工作!
    • 在此示例中我没有看到任何与文件系统相关的内容。我还查看了 Ember 的 github 帐户中的内容,特别是您提到的测试。我在这些测试中也看不到任何文件系统的东西。所以我对如何从文件夹加载任何文件感到困惑。
    • 这个问题并不是关于文件系统,而是关于{{partial}} 助手的工作方式。 Ember 不加载文件 - 这可能由 sprockets(在 rails 应用程序中)或类似 requirejs 之类的东西完成。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-06
    相关资源
    最近更新 更多