Reputation: 15309
In my object i have a data like this :
naviObj = {"Home":"homelink","Service":"sericeLink","Contact":"contactLink"}
from this, i should make a link text from key's of object and links href should be the value of each key.. i tried this way..
naviObj = {"Home":"homelink","Service":"sericeLink","Contact":"contactLink"}
var naviMaker = function(){
var naviHtml = Handlebars.compile($("#navigation").html());
$("nav ul").append(naviHtml(naviObj));
}
naviMaker();
I am looking the result should be :
<ul>
<li><a href="homelink">Home</a></li>
<li><a href="sericeLink">Service</a></li>
<li><a href="contactLink">Contact</a></li>
</ul>
I am getting the link text as well the object value.. but i don't know to ket the key to text of link..
any one help me to solve this please..?
here is the jsfiddle
On google search i got an answer here : enter link description here, still any one give short approach appreciated. thanks.
Upvotes: 0
Views: 431
Reputation: 601
Here is the Solution.JFIDDLE http://jsfiddle.net/ganeshprabhu1994/4qnaM/
HTML
<ul></ul>
Script
$(function()
{
naviObj = {"Home":"homelink","Service":"sericeLink","Contact":"contactLink"};
for(property in naviObj)
{
$('ul').append("<li><a href='"+naviObj[property]+"'>"+property+"</a></li>");
}
});
Upvotes: 1