I can't use the value of an array to set an HTML attribute
I'm trying to set an html attribute on an eps template, the template looks like this....
<table class="table table-striped table-hover">
<tbody id="jobTable">
<% Object.keys(resRtn.hits).forEach(function(n) { %>
<tr>
<td> <a href="/getJob?<%- resRtn.hits[n]._source.IndexName %>" > <%- resRtn.hits[n]._source.Name %></a></td>
<td> <%- resRtn.hits[n]._source.Headline%> </td>
<td> <%- resRtn.hits[n]._source.Status%> </td>
</tr>
<% }); %>
</tbody>
</table>
The data set is this ...
"resRtn": {
"total": {
"value": 3,
},
"hits": [
{
"_source": {
"IndexName”: “jobIndex1",
"Status": "New",
"Headline": "Headline 1",
"Name": "Job-Title-1",
"CreationDate": 1582310090612
}
},
{
"_source": {
"IndexName”: “jobIndex2",
"Status": "New",
"Headline": "Headline 2",
"Name": "Job-Title-2",
"CreationDate": 1582310090633
}
},
{
"_source": {
"IndexName”: “jobIndex3",
"Status": "New",
"Headline": "Headline 3",
"Name": "Job-Title-3",
"CreationDate": 1582310090444
}
}
]
}
Focusing on this particular part of the template
<td><a href="/getJob?<%-resRtn.hits[n]._source.IndexName %>"><%- resRtn.hits[n]._source.Name %></a></td>
It renders like this ....
<a href="/getJob?"> Job-Title-1</a>
<a href="/getJob?"> Job-Title-2</a>
<a href="/getJob?"> Job-Title-3</a>
The resRtn.hits[n]._source.Name (the Job Title) renders fine but the addition to the href doesn't get added.
It appears to be an issue with the fact that I'm using the variable 'n' to access a position in the array, if change the eps template to ....
<td><a href="/getJob?<%-resRtn.total.value %>"><%- resRtn.hits[n]._source.Name %></a></td>
And directly reference a specific value it works and renders the following ...
<a href="/getJob?3"> Job-Title-1</a>
<a href="/getJob?3"> Job-Title-2</a>
<a href="/getJob?3"> Job-Title-3</a>
How can I set the HTML href value using a value in an array?
Any help would be greatly appreciated!!!