I use the templates and javascript to generate the htmls for an json data, this is the tempalte:
<div id="template">
<div class="iwContainer">
<div class="iwHeaderContainer">
<div class="iw-title-container">
<span class="titleText">${name}</span> <a target="_blank" href="detail?fid=${id}" class="titleLink">Detail</a>
</div>
</div>
<div class="iwRichContainer">
<div class="iw-g-font">Address:${address}</div>
</div>
@{setsearchTemplate}
</div>
</div>
Js:
buildInfoContent : function(item) {
var tmp = $("#template").html();
if (tmp) {
tmp = tmp.replace(/\$\{(\w*)\}/g, function(m, key) {
return item.hasOwnProperty(key) ? item[key] : "";
});
return tmp;
}
}
And I call it:
buildInfoContent({name:'name',id:2,address:'address'});
And all of the palcehodler are replaced but the ${id}.
Through firebug I found that the temlate is something like this:
.........<span class="titleText">${name}</span> <a target="_blank" href="detail?fid=$%7bid%7d" class="titleLink">Detail</a>.......
So the id is not replaced, how to fixe it?
{ }toother character?