简体   繁体   English

如何访问车把帮手中的父项?

[英]How to access parent item in handlebars helpers?

I have a template. 我有一个模板。

{{#each dbModel in model}}
<h2>Database Name : {{dbModel.databaseName}}</h2>
<h3>Select Table: 
                     {{view Ember.Select
                          content=dbModel.tables
                          optionValuePath="content.tableName"
                          optionLabelPath="content.tableName"  
                          valueBinding = "dbModel.selectedTable"
                          selectBinding = "dbModel.selectedTable"
                    }}
</h3>
<h2>Selected Table is : {{dbModel.selectedTable}}</h2>
{{#each table in dbModel.tables}}
  {{dbModel.selectedTable}}       
  {{#matchTable table.tableName dbModel.selectedTable}}
      //Get fields is selected table match with table name
  {{/matchTable}}
{{/each}}

Now In the matchTable helper I am getting value of table.tableName but for dbModel.selectedTable is undefined . 现在,在matchTable帮助器中,我正在获取table.tableName值,但是对于dbModel.selectedTable is undefined

dbModel.selectedTable is not part of actual model, I have added this to controller as follows. dbModel.selectedTable不是实际模型的一部分,我将其添加到控制器中,如下所示。

App.DatabaseController = Ember.ArrayController.extend({
    selectedTable:[],
    actions: {
        cancel: function () {
         // something
        }
    }
});

When I change the value of select it automatically updates the information in <h2> tag. 当我更改select的值时,它会自动更新<h2>标记中的信息。 So it means that the value is setting and got bind properly. 因此,这意味着该值正在设置并正确绑定。 But for helper when I try to pass it it simply shows undefined. 但是当我尝试通过它的帮助者时,它只是显示未定义。 I searched and found that can use ../dbModel.selectedTable . 我搜索发现可以使用../dbModel.selectedTable Still it is undefined. 仍然是不确定的。 Anyone please guide. 任何人请指导。
What is the way to pass the parent to the helper in each loop? 在每个循环中将父级传递给助手的方法是什么?

Your #each loop drops you into the scope of the tables array. 您的#each循环将您带入tables数组的范围。 ../ places you in the scope of the dbModel object. ../将您置于dbModel对象的范围内。 To access selectedTable within the loop, use ../selectedTable 要在循环中访问selectedTable ,请使用../selectedTable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM