I have some JSON I'm passing to a partial view.
{
"0": {
"storename": "Park plaza",
"prediction": "Retail Sites",
"probability": 0.851005
},
"1": {
"storename": "Emory Mills",
"prediction": "Retail Sites",
"probability": 0.851005744010425
},
"2": {
"storename": "Potamac Heights",
"prediction": "Retail Sites",
"probability": 0.851005744010425
}
}
And here's the code for the loop.
<% for(var i=0; i < tabledata.length; i++) { %>
<tr>
<td><%= tabledata[i].storename %></td>
<td><%= tabledata[i].prediction %></td>
</tr>
<% } %>
I'm curious as to why this doesn't work, but without a loop, it does.
<tr>
<td><%- tabledata["0"].storename %></td>
<td><%- tabledata["0"].prediction %></td>
</tr>
<tr>
<td><%- tabledata["1"].storename %></td>
<td><%- tabledata["1"].prediction %></td>
</tr>
<tr>
<td><%- tabledata["2"].storename %></td>
<td><%- tabledata["3"].prediction %></td>
</tr>
I realized that even without the loop, I needed the numbers as strings. However, even when I put i.toString() in the loop, it says that there is a typeerror. I also tried putting in quotes "", as well as single quotes '' but that also didn't work.
Also, the errors I see are Syntax error, unexpected token ILLEGAL in my partial view.
Any thoughts?