I have this template:
var temp = "<div class="${class}" id="loc" data-res="${res}"></div>";
and i would like to replace ${res} with an array, so I can later do something like that:
$('#loc').data('res');
I tried this:
var res = [["a","b"],["c","d"]];
var arr = { class: "bold", res: res};
var newtemp = rep(temp, arr);
function rep(temp, arr)
{
return temp.replace(/\$\{([\w]+)\}/g, function(s1, s2) {
var s = arr[s2];
if (typeof (s) != "undefined"){
return s;
} else {
return s1; }
});
}
But no way... for the ${res} sustitution and keep formated like an array. I would like this result:
<div class="bold" id="loc" data-res='[["a","b"],["c","d"]]'></div>