琥珀产量参数通过 [英] Ember yield param passing
本文介绍了琥珀产量参数通过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将一个参数传递给一个yield块,但是我缺少一些我看不到的内容。以下是这种情况:
I'm trying to pass an argument to a yield block, however I missing something that I don't see. Here is the case:
components / table-notes.hbs
<table>
...
<tbody>
{{#each note in notes}}
<tr>
<td>{{yield note}}</td>
...
</tr>
{{/each}}
</tbody>
</table>
其他地方
{{#table-notes notes=model.notes}}
//do something with each note
{{/table-notes}}
此参数传递是否有任何错误或不完整?
Is it anything wrong or incomplete with this param passing?
提前感谢
推荐答案
我不认为你可以在1.10之前的版本中做到这一点。在1.10中,您可以 执行以下操作:
I don't think you can do this in a version prior to 1.10. In 1.10 though, you can do the following:
声明组件模板和 yield
<script type="text/x-handlebars" id="components/table-notes">
{{#each notes as |note|}}
{{ yield note }}
{{/each}}
</script>
并且还在模板中声明使用变量所调用的组件 note
如下:
And also declare in the template using the component that the variable is called note
as follows:
<script type="text/x-handlebars" data-template-name="index">
{{#table-notes notes=model.notes as |note|}}
<h3>{{ note }}</h3>
{{/table-notes}}
</script>
工作示例这里
您可以阅读有关组件中的块参数的更多信息,1.10中的新功能, here 。
You can read more about block params in components, a new feature in 1.10, here.
这篇关于琥珀产量参数通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文