【发布时间】:2019-12-25 20:32:05
【问题描述】:
我正在使用 Ember v2.5.1。
我正在尝试这个解决方案,因为我需要在同一个组件中使用两个自定义产量:
How can I yield multiple pieces of content into an ember.js component template?
这是我的代码:
// component
{{#father-component as |f|}}
{{#f.left-content}}
This is a content
{{/f.left-content}}
{{#f.right-content}}
This is a another content
{{/f.right-content}}
{{/father-component}}
// father-component
<div class="left">
{{yield (hash left-content = (component "foo-content"))}}
</div>
<div class="right">
{{yield (hash right-content = (component "foo-content"))}}
</div>
// foo-content
{{yield}}
在https://ember-twiddle.com/ 这个works nicelly 中,但在我的本地主机中这不起作用并返回此错误
断言失败:找不到名为“f.right-content”的助手
有什么帮助吗?
我使用应用程序导出组件,并分别导出 js 和 hbs 路径。
编辑
当我在父组件中添加 {{log f}} 时会发生这种情况。
【问题讨论】:
-
我会仔细检查您的模板以确保没有错字。这在旋转中起作用的事实表明它可能是一个简单的错误。为了安全起见,也许可以将旋转模板/组件文件复制粘贴到您的本地项目中。
-
试试
f.rightContent和f.leftContent? -
嗯..我使用的是ember +v2.5,我尝试了两个cmets但仍然发生同样的错误=(
Assertion Failed: A helper named 'f.rightContent' could not be found -
@MarceloBoni 尝试在父组件模板块中记录
f:{{log "f is: " f}} -
我去在问题中添加快照。
标签: ember.js