问题
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