Html 使用Ember把手中嵌套的每个块时的上下文绑定
我只是偶然发现了emberJS,并认为它值得在我的下一个web应用程序中试用 我实际上计划做的是以二维方式显示对象列表(这可以是一个表) 到目前为止,我所拥有的:Html 使用Ember把手中嵌套的每个块时的上下文绑定,html,ember.js,handlebars.js,templating,Html,Ember.js,Handlebars.js,Templating,我只是偶然发现了emberJS,并认为它值得在我的下一个web应用程序中试用 我实际上计划做的是以二维方式显示对象列表(这可以是一个表) 到目前为止,我所拥有的: <script type="text/x-handlebars"> <table width="100%" style="text-align:left"> <tr> <th> </th> {{#each App.MyController.getC
<script type="text/x-handlebars">
<table width="100%" style="text-align:left">
<tr>
<th>
</th>
{{#each App.MyController.getColumnValues}}
<th>{{this}}</th>
{{/each}}
</tr>
{{#each App.MyController.getRowValues}}
<tr>
<th>{{this}}</th>
{{#each App.MyController.getColumnValues}}
{{view App.CountView rowBinding="this" columnBinding="../this"}}
{{/each}}
</tr>
{{/each}}
</table>
</script>
{{{#each App.MyController.getColumnValues}
{{this}}
{{/每个}}
{{{#each App.MyController.getRowValues}
{{this}}
{{{#each App.MyController.getColumnValues}
{{view App.CountView rowBinding=“this”columnBinding=“../this”}
{{/每个}}
{{/每个}}
对于countView:
<script type="text/x-handlebars" data-template-name="countView">
<td>{{view.row}} - {{view.column}}</td>
</script>
{{view.row}}-{{view.column}
正如您可能看到的,我希望在每个单元格中都有当前列和行的值。
除了列绑定之外,一切都正常。正如我在Handlebars的页面上读到的,{{../this}是解决父模板作用域的方法。在两个花括号中(无需为其创建额外视图),此操作非常有效。
但我后来需要调用一个函数,将列和行的值传递给它,并认为(为了使它更清晰),此时最好是一个视图
您知道如何访问父模板作用域并将其传递给countView吗?为了避免混淆,您可以始终在
{{each}
块中使用变量,在这种情况下,您可以尝试以下方法:
{{#each row in App.MyController.getRowValues}}
<tr>
<th>{{row}}</th>
{{#each column in App.MyController.getColumnValues}}
{{view App.CountView rowBinding="row" columnBinding="column"}}
{{/each}}
</tr>
{{/each}}
{{{App.MyController.getRowValues}中的每一行
{{row}}
{{{App.MyController.getColumnValues中的每一列}
{{view App.CountView rowBinding=“row”columnBinding=“column”}
{{/每个}}
{{/每个}}
让我知道这是否有帮助…这很有效。非常感谢。在阅读《Ember指南》时,没有遇到在每个循环中命名项目的问题。你可能知道一些教程或更好的说明吗?Ember API不是很清晰。这可以在emberjs网站的API部分中找到,而不是在文档中。你还可以访问更多详细信息led信息,其中包括编写自己的助手,这正是我要找的。再次非常感谢:)