在收益中访问当前模型 [英] Accessing the current model within a yield
问题描述
我正在寻找如何使用yield语句访问当前模型。任何想法?
模型
模型:[{
id:1,
name:'Red',
value:'#ff0000'
},{
id:2,
'name':'Yellow',
value:'#ffff00'
},{
id:3,
name:'Blue',
value:'# 0000ff'
}];
模板
< pre $ {{#table-list models = models config = colorModelTableListConfig}}
{{model.id}}
{{model.name}}
{{model.value}}
{{/ table-list}}
组件(表列表)
<! - 搜索标记 - >
< table>
{{#each th in config.tableHeaders}}
< th> {{th}}< / th>
{{/ each}}
{{#模型中的每个模型}}
{{yield}}
{{/每个}}
< /表>
<! - 分页标记 - >
附注这会导致我的搜索,分页和其他功能的问题。
答案 您可以将参数传递给yield块: 如果需要,您可以调整其他名称: 您可以使用每个助手做类似的事情: I'm looking for how to access the current model with-in an each from a yield statement. Any ideas? Model Template Component (table-list) Side-note I can't throw the each inside the yield, this will cause issues with my searching, pagination and other functionality Answer You can pass parameters to the yield block: If necessary you can adjust for a different name: You can do something similar using the each helper: 这篇关于在收益中访问当前模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
{{yield model}}
{{#with model as foobar}}
{{yield foobar}}
{{/ with}}
{{#模型中的每个模型都是| foobar |}}
{{yield foobar}}
{{/ 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}}
<!-- Searching markup-->
<table>
{{#each th in config.tableHeaders}}
<th>{{th}}</th>
{{/each}}
{{#each model in models}}
{{yield}}
{{/each}}
</table>
<!-- Pagination markup-->
{{yield model}}
{{#with model as foobar}}
{{yield foobar}}
{{/with}}
{{#each model in models as |foobar|}}
{{yield foobar}}
{{/each}}