在收益范围内访问当前模型
Accessing the current model within a yield
我正在寻找如何通过 yield 语句在 each 中访问当前模型。有什么想法吗?
型号
models: [{
id: 1,
name:'Red',
value: '#ff0000'
}, {
id: 2,
name:'Yellow',
value: '#ffff00'
}, {
id: 3,
name:'Blue',
value: '#0000ff'
}];
模板
{{#table-list models=models config=colorModelTableListConfig}}
{{model.id}}
{{model.name}}
{{model.value}}
{{/table-list}}
组件(table-列表)
<!-- Searching markup-->
<table>
{{#each th in config.tableHeaders}}
<th>{{th}}</th>
{{/each}}
{{#each model in models}}
{{yield}}
{{/each}}
</table>
<!-- Pagination markup-->
旁注我不能将 each 放入 yield 中,这会导致我的搜索、分页和其他功能出现问题
回答
您可以将参数传递给 yield 块:
{{yield model}}
如有必要,您可以调整为不同的名称:
{{#with model as foobar}}
{{yield foobar}}
{{/with}}
您可以使用 each 助手执行类似的操作:
{{#each model in models as |foobar|}}
{{yield foobar}}
{{/each}}
我正在寻找如何通过 yield 语句在 each 中访问当前模型。有什么想法吗?
型号
models: [{
id: 1,
name:'Red',
value: '#ff0000'
}, {
id: 2,
name:'Yellow',
value: '#ffff00'
}, {
id: 3,
name:'Blue',
value: '#0000ff'
}];
模板
{{#table-list models=models config=colorModelTableListConfig}}
{{model.id}}
{{model.name}}
{{model.value}}
{{/table-list}}
组件(table-列表)
<!-- Searching markup-->
<table>
{{#each th in config.tableHeaders}}
<th>{{th}}</th>
{{/each}}
{{#each model in models}}
{{yield}}
{{/each}}
</table>
<!-- Pagination markup-->
旁注我不能将 each 放入 yield 中,这会导致我的搜索、分页和其他功能出现问题
回答
您可以将参数传递给 yield 块:
{{yield model}}
如有必要,您可以调整为不同的名称:
{{#with model as foobar}}
{{yield foobar}}
{{/with}}
您可以使用 each 助手执行类似的操作:
{{#each model in models as |foobar|}}
{{yield foobar}}
{{/each}}