Reputation: 813
I am new to javascript. I am not able to construct a href tag with a variable appended. Below is the code and I want to append the tag_id to the href attribute.
Desired href format: /dashboard/#/summary/1008 Current href format: /dashboard/#/summary/
function(data, type, full) {
return ( data == null ) ? "--" :"<span class='label label-success'><a href='/dashboard/#/summary/'+ tag_id>"+ data.tag_name+"</a></span>" ;
}
Could you please let me know where I am going wrong. Please help me in fixing this issue.
Upvotes: 0
Views: 43
Reputation: 2926
You are getting data.tag_name. Same as you have to get tag_id as well. This is basic idea
Example: <a href="http://www.example.com/summarry/**value_id**">**Value_name**</a>
Same idea we have to use here
function(data, type, full) {
return ( data == null ) ? "--" :"<span class='label label-success'><a href='/dashboard/#/summary/'+ data.tag_id>"+ data.tag_name+"</a></span>" ;
}
Upvotes: 1
Reputation: 146249
Change following:
"<span class='label label-success'><a href='/dashboard/#/summary/'+ tag_id>"+ data.tag_name+"</a></span>"
To this:
"<span class='label label-success'><a href='/dashboard/#/summary/" + tag_id + "'>" + data.tag_name + "</a></span>"
Also, make sure tag_id
is available within the scope of your function. I think tag_id
should be data.tag_id
because you have data.tag_name
unless you have another tag_id
in the global scope. So, according o that, it should be:
"<span class='label label-success'><a href='/dashboard/#/summary/" + data.tag_id + "'>" + data.tag_name + "</a></span>"
Upvotes: 1
Reputation: 8261
Try this. Will work. I think it will be data.tag_id. But considering tag_id will be available to you.
function(data, type, full) {
return ( data == null ) ? "--" :"<span class='label label-success'><a href='/dashboard/#/summary/'"+tag_id+">"+ data.tag_name+"</a></span>" ;
}
Upvotes: 1