Reputation: 107
I am getting data from an api and sending it to home.ejs file and displaying it.I get this error after I include the line:
<p><%= data[i].blocks.requestedBodyBlocks.body:latest:1[0].bodyHtml %></p>
The api is providing the data properly because when I run the requested url on google it works fine. Please help.
SyntaxError: missing ) after argument list in C:\Users\HP\Desktop\NEWS\views\home.ejs while compiling ejs.
home.ejs
<%- include('header') %>
<div id="news">
<% for(var i=0;i<data.length;i++){ %>
<div id="post">
<div data-toggle="collapse" data-target="#collapse<%= i%>" aria-expanded="false">
<p><%=data[i].webTitle%></p>
<p><%=data[i].fields.trailText %></p>
<p><%=data[i].fields.byline %></p>
<p><%=data[i].webPublicationDate %></p>
</div>
<div class="collapse" id="collapse<%= i%>" >
<div class="card card-body">
<p><img src=<%= data[i].fields.thumbnail %> ></p>
<p>Bodyyyyyyyyyyyyyyyyyyyyyyyyyyyyy</p>
<p><%= data[i].blocks.requestedBodyBlocks.body:latest:1[0].bodyHtml %></p>
</div>
</div>
</div>
<% } %>
</div>
Upvotes: 0
Views: 64
Reputation: 14423
When you have colons :
in your json object's keys (or characters which are valid tokens in JS, like -
, &
, etc.), you need to use the ["keyname"]
notation.
In your case, it would be:
data[i].blocks.requestedBodyBlocks["body:latest:1"][0].bodyHtml
Upvotes: 2