1

Here I'm passing id which stored in m, please help me how to pass id. and call that page using that id. I'm using the embedded JavaScript template as a view engine please help.

   $.each(products, function(index, product ) {

            var m= product['_id'];
            //document.write(alert(m));
            string += '<tr><td>'+(index+1)+'</td><td>'+product['_id']+'</td><td>'+product['name']+'</td><td>'+product['category']+'</td><td>'+product['price']+'</td><td>'+product['manufacturer']+'</td><td><a href="/profile/dashboard/update/{{m}}">Update</a> </td></tr>';
        });

route code

 app.get('/profile/dashboard/update/:m',function (req,res,next) {
       console.log("hi"+req.params.m); 
      });
Gaurav joshi
  • 1,743
  • 1
  • 14
  • 28
EasyFreeNotes
  • 17
  • 1
  • 7

3 Answers3

0

You need to use this quotes `` for template string;

as example:

var m = 1;
var string = `id: ${m}`
At At
  • 21
  • 4
0

`... <a href=/profile/dashboard/update/${product['id']}>Update</a> </td></tr>`

You need to wrap your whole string in backticks and pass the variables as written above ( ${var_name} ). See this answer for more info. This isn't a NodeJS question, more of a Javascript question itself.

Milan Velebit
  • 1,933
  • 2
  • 15
  • 32
0
string += '<tr><td>'+(index+1)+'</td><td>'+product['_id']+'</td><td>'+product['name']+'</td><td>'+product['category']+'</td><td>'+product['price']+'</td><td>'+product['manufacturer']+'</td><td><a href="profile/dashboard/update/'+id+'">Update</a> </td></tr>';

It will work