Accessing the current model within a yield

假如想象 提交于 2020-01-17 04:41:13

问题


I'm looking for how to access the current model with-in an each from a yield statement. Any ideas?

Model

models: [{
   id: 1,
   name:'Red',
   value: '#ff0000'
}, {
  id: 2,
  name:'Yellow',
  value: '#ffff00'
}, {
  id: 3,
  name:'Blue',
  value: '#0000ff'
}];

Template

{{#table-list models=models config=colorModelTableListConfig}}
  {{model.id}}
  {{model.name}}
  {{model.value}}
{{/table-list}}

Component (table-list)

<!-- Searching markup-->
<table>
  {{#each th in config.tableHeaders}}
    <th>{{th}}</th>
  {{/each}}

  {{#each model in models}}
    {{yield}}
  {{/each}}
</table>
<!-- Pagination markup-->

Side-note I can't throw the each inside the yield, this will cause issues with my searching, pagination and other functionality

Answer

Ember yield param passing


回答1:


You can pass parameters to the yield block:

{{yield model}}

If necessary you can adjust for a different name:

{{#with model as foobar}}
  {{yield foobar}}
{{/with}}

You can do something similar using the each helper:

{{#each model in models as |foobar|}}
  {{yield foobar}}
{{/each}}

More examples: https://github.com/emberjs/ember.js/blob/06e41ad7ccd28558dd4e651aa070bc06f7757821/packages/ember-htmlbars/tests/integration/block_params_test.js



来源:https://stackoverflow.com/questions/29851163/accessing-the-current-model-within-a-yield

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