In Handlebars.js, how can I use @index to subscript into another parallel array in the object I am passing to a template?
For example, say I have an object set up like the following:
var table = {
cols : [
{ name: "Column 1" },
{ name: "Column 2" },
{ name: "Column 3", highlighted: true }
],
rows : [
{
label: "Row 1",
data: [
{ val: 5 },
{ val: 3 },
{ val: 8 }
]
},
{
label: "Row 2",
data: [
{ val: 8 },
{ val: 4 },
{ val: 0 }
]
}
]
};
I need to be able to use the @index from an {{#each rows}}{{#each data}} loop to check if the column is highlighted to apply a style to cells in the column, but Handlebars.js does not appear to allow using @index in a subscript operator.
E.g.
{{@index}} <!-- Index of current rows.data is 2. -->
{{#if ../../cols.[@index].highlighted }}
<!-- Never Executed -->
{{/if}}
{{#if ../../cols.[2].highlighted }}
<!-- Executes -->
{{/if}}
Is this not supported? Am I doing something wrong? How can I get this to work easily?
I posted an example on jsfiddle.net.
{{#if ../../[email protected] }}does not work either, causing the parse errorExpecting 'ID', got 'DATA'.highlighted: trueto each column cell that should be highlighted? I guess I can do that, but it seemed like unnecessary duplication of data.colsto make it easier to access the currently hilighted column in Handlebars.