本文介绍了在收益中访问当前模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在寻找如何使用yield语句访问当前模型。任何想法? 模型 模型:[{ 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> {{#each th in config.tableHeaders}} < th> {{th}}< / th> {{/ each}} {{#模型中的每个模型}} {{yield}} {{/每个}} < /表> 附注这会导致我的搜索,分页和其他功能的问题。 答案 Ember yield param pass 解决方案 您可以将参数传递给yield块: {{yield model}} 如果需要,您可以调整其他名称: {{#with model as foobar}} {{yield foobar}} {{/ with}} 您可以使用每个助手做类似的事情: {{#模型中的每个模型都是| foobar |}} {{yield foobar}} {{/ each}} 更多示例: https://github.com/emberjs/ember.js/blob/06e41ad7ccd28558dd4e651aa070bc06f7757821/packages/ember-htmlbars/tests/integration/block_params_test。 js I'm looking for how to access the current model with-in an each from a yield statement. Any ideas?Modelmodels: [{ 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 functionalityAnswerEmber yield param passing 解决方案 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 这篇关于在收益中访问当前模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-25 01:54