Solution 1 :

I see a few problems.

First, you are trying to step-up a context-level from within your #each using ./row. However, the correct syntax for this is two dots, ../row.

Secondly, when you step-up a context-level, by using ../row you are trying to access a row property on the parent context. But the parent does not have a row property because the parent is the row object. So the correct reference would be .. instead of ../row.

Third, Handlebars does not support dynamic key evaluation with square brackets. You need to use the lookup helper to do this evaluation, {{lookup .. @key}}.

I have created a fiddle for your reference.

Solution 2 :

First of all, Thanks @76484 for your answer.
Second I had got my answer on my own, and its quite similar to answer given by him.
I achieved the solution to my question with the following syntax.

{{#each data as | row |}}
    <td>
        {{row.name}}
    </td>

{{#each ../keyPairs}}
    <td>
        {{lookup row @key}}
    </td>
{{/each}}
{{/each}}

Problem :

I have data as follows where keyPairs is dynamic columns of a table and data has the row data.

keyPairs: {
"key0":"Value0",
"key1":"Value1",
    ...
}

data:[
{
"name":"name0",
"key0":"Value0",
"key1":"---",
},

{
"name":"name1",
"key0":"---",
"key1":"Value1",
}]

The keyPairs object is dynamically created, and the keys used in each object in the data array are the same as the keys in keyPairs. I am unable get the values for each data item with each @key from keyPairs.

{{#each data as | row |}}
    <td>
        {{row.name}}
    </td>

{{#each ../keyPairs}}
    <td>
        {{./row[@key]}}
    </td>
{{/each}}
{{/each}}

Comments

Comment posted by Sahyog Vishwakarma

thanks for your answer. but I had already done with it by self with some hit and trials.

Comment posted by 76484

@SahyogVishwakarma: That’s great! For the future, I would recommend posting your solution so that those with the same issue can learn from it and potential responders will know you no longer need their help.

By