javascript - Ember 模板约定

标签 javascript ember.js discourse

我正在尝试了解 Discourse 中的 EmberJS 模板约定。 这是来自 app/assets/javascripts/discourse/templates/discovery/categories.hbs

的片段
{{#discovery-categories refresh="refresh"}}
  {{component controller.categoryPageStyle
              categories=model.categories
              latestTopicOnly=controller.latestTopicOnly
              topics=model.topics}}
  {{!-- my-template --}}
{{/discovery-categories}}

discovery-categoriescomponent 的含义是什么? 例如,我想插入 my-template 来扩展 categories.hbs,我应该使用什么约定来使用模板创建文件?

最佳答案

  1. discovery-categories 是组件的名称 使用组件名称静态调用。

  2. 第二行中的“组件”是一个模板助手,它使用通过属性 controller.categoryPageStyle 指定的名称动态加载组件。

3.my-template 是yield block ,您可以在其中获取组件discovery-categories(如果其yield)的上下文。 例如。如果 discovery-categories 有一个属性 foo 你可以写类似

{{#discovery-categories refresh="refresh" foo="Some Text"}}
  {{component controller.categoryPageStyle
              categories=model.categories
              latestTopicOnly=controller.latestTopicOnly
              topics=model.topics}}
  {{foo}}
{{/discovery-categories}}

关于javascript - Ember 模板约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40218133/

相关文章:

javascript - 循环遍历 Backbone $el 中的 tr 元素

javascript - 检查 Cypress 中的单选按钮

Ember.js新路由器: accessing serialized objects from parent dynamic route segments

javascript - 需要 ember 模型返回数组 promise 而不是对象

javascript - 引用错误: Can't find variable - Qunit Testing with ember in rails

ruby-on-rails - 从命令行调试/执行 Discourse 插件

javascript - Grails 3 - 资源插件

javascript - jQuery Mobile 中的背景图像

ruby-on-rails - 我刚刚部署了 discourse 应用程序,在 Heroku db :migrate. 期间出现错误,可能是 redis 无法连接

ruby-on-rails - 无法使用 gmail smtp 服务器发送邮件(在讨论中)