简体   繁体   中英

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 .

dbModel.selectedTable is not part of actual model, I have added this to controller as follows.

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. 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 . 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. ../ places you in the scope of the dbModel object. To access selectedTable within the loop, use ../selectedTable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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