I'm looking for how to access the current model with-in an each from a yield statement. Any ideas?
我正在寻找如何从yield语句中使用每个访问当前模型。有任何想法吗?
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屈服于传递
1 个解决方案
#1
1
You can pass parameters to the yield block:
您可以将参数传递给yield块:
{{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}}
更多示例:https://github.com/emberjs/ember.js/blob/06e41ad7ccd28558dd4e651aa070bc06f7757821/packages/ember-htmlbars/tests/integration/block_params_test.js
#1
1
You can pass parameters to the yield block:
您可以将参数传递给yield块:
{{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}}
更多示例:https://github.com/emberjs/ember.js/blob/06e41ad7ccd28558dd4e651aa070bc06f7757821/packages/ember-htmlbars/tests/integration/block_params_test.js