I am facing an issue with loading data from a JSON file into an array in the correct format:
var jobs = [
{ ID: 'grt34hggdggf', Employer: 'A1', Title: 'tobi1', Location: 'Los Angeles, CA', Department: 'department', OpeningDate: '2012-12-26T01:29Z', ClosingDate: '2013-04-26T01:29Z', MinSalary: '30000', MaxSalary: '60000', Description: 'bla-gghrf-bla' },
{ ID: 'grt34hgwerwgf', Employer: 'A2', Title: 'tobi2', Location: 'Los Angeles, CA', Department: 'department', OpeningDate: '2012-12-26T01:29Z', ClosingDate: '2013-04-26T01:29Z', MinSalary: '30000', MaxSalary: '60000', Description: 'bla-gghrf-bla' }
];
The current format does not seem to work as expected with views. I have attempted to adjust my JSON file to match the required format:
{
"jobs":[
{ "ID": "grt34hggdggf", "Employer": "A1", "Title": "tobi1", "Location": "Los Angeles, CA", "Department": "department", "OpeningDate": "2012-12-26T01:29Z", "ClosingDate": "2013-04-26T01:29Z", "MinSalary": "30000", "MaxSalary": "60000", "Description": "bla-gghrf-bla" },
{ "ID": "grt34hggdggf", "Employer": "A2", "Title": "tobi1", "Location": "Los Angeles, CA", "Department": "department", "OpeningDate": "2012-12-26T01:29Z", "ClosingDate": "2013-04-26T01:29Z", "MinSalary": "30000", "MaxSalary": "60000", "Description": "bla-gghrf-bla" }
]
}
However, when attempting to run a "forEach" loop in the view, I encounter the following error:
TypeError: F:\tmp\express-master\examples\ejs\views\result.html:5
3|
4| <table>
>> 5| <% jobs.forEach(function(job){ %>
6| <tr>
7| <td>
8| <a href="/job/<%= job.ID %>"><%= job.Title %></a>
Object #<Object> has no method 'forEach'
It appears that the JSON file may still be in an incorrect format. How can I resolve this issue?