Karan Dutta
Karan Dutta

Reputation: 63

How to fix the EJS syntax error: "missing ) after argument list"

I'm trying to fix this error, but I am not able to figure out where the problem is. I'm just printing out a JSON file in EJS dynamically.

My routing file:

      ExcelRoute.get('/table', (req, res) => {
           var guest = 'karan'
            var myData = [{
      "Main Category": "Men",
      "Category": "Shoes",
      "Sub-Category": "Running"
    },
    {
      "Main Category": "Women",
      "Category": "Clothing",
      "Sub-Category": "Tees"
    },
    {
      "Main Category": "Kids",
      "Category": "Accessories",
      "Sub-Category": "Bags"
    },
    {
      "Main Category": "Sports",
      "Category": "Sport",
      "Sub-Category": "Training"
    },
    {
      "Main Category": "Collection",
      "Category": "",
      "Sub-Category": ""
    },
    {
      "Main Category": "Sale",
      "Category": "",
      "Sub-Category": ""
    },
    {
      "Main Category": "",
      "Category": "",
      "Sub-Category": ""
    },
    {
      "Main Category": "",
      "Category": "",
      "Sub-Category": ""
    },
    {
      "Main Category": "",
      "Category": "",
      "Sub-Category": ""
    },
    {
      "Main Category": "",
      "Category": "",
      "Sub-Category": ""
    },
    {
      "Main Category": "",
      "Category": "",
      "Sub-Category": ""
    }
  ]

        res.render('indexpage', {
        user: myData,
        guest: guest
        })
      })

I've been using EJS to print an array of objects using EJS. But it is giving me an error:

missing ) after argument list.

My HTML file code

          <form method="GET" action="table">
            <button onclick="loadTable()">GenTable</button>
          </form>

My EJS file code:

    <body>
        <h1>Welcome <%=guest%></h1>
        <ul>
            <% user.forEach((menu)=>{ %>
                <a href="#"><li><%=menu.Main Category%></li></a>
                <a href="#"><li><%=menu.Category%></li></a>
                <a href="#"><li><%=menu.Sub Category%></li></a>
            <% }) %>
        </ul>
    </body>

Upvotes: 3

Views: 1179

Answers (1)

dimitris tseggenes
dimitris tseggenes

Reputation: 3186

You should enclose each property in brackets.

<% user.forEach((menu)=>{ %>
     <a href="#"><li><%=menu['Main Category']%></li></a>
     <a href="#"><li><%=menu['Category']%></li></a>
     <a href="#"><li><%=menu['Sub Category']%></li></a>  
 <% }) %>

Upvotes: 2

Related Questions