<\/script>')

JQuery Templates, escape "$ {...}"

I have javascript code like this:

var data = { ... };
var template = "<select>" +
                 "<option value='${0:###,###.##}'>Format as $</option>" + 
               "</select>";

$.tmpl(template, data).appendTo("#placeholder");

      

My problem is I want to evaluate "value = '$ {0: ###, ###. ##}'" as a string, but jQuery templates try to evaluate it as an object reference.

Is there a way to escape the $ {} characters?

Cheers, Shane

+3


source to share


1 answer


Try replacing $ with a special HTML character &#36;



var data = { };
var template = "<select>" +
         "<option value='&#36;{0:###,###.##}'>Format as $</option>" + 
       "</select>";

$.tmpl( template, data).appendTo("#placeholder");

      

+5


source







All Articles