Ember yield param passing

南楼画角 提交于 2019-12-12 12:05:14

问题


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>

elsewhere

{{#table-notes notes=model.notes}}
  //do something with each note
{{/table-notes}}

Is it anything wrong or incomplete with this param passing?

Thanks in advance.


回答1:


I don't think you can do this in a version prior to 1.10. In 1.10 though, you can do the following:

Declare the component template and yield

<script type="text/x-handlebars" id="components/table-notes">
   {{#each notes as |note|}}
    {{ yield note }}
   {{/each}}
</script>

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>

Working example here

You can read more about block params in components, a new feature in 1.10, here.



来源:https://stackoverflow.com/questions/28989968/ember-yield-param-passing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!