Gordon Thompson
Gordon Thompson

Reputation: 4824

Escaping colons in JQuery Templates

I have the following JQuery Template

<script id="SearchResultsTemplate" type="text/x-jquery-tmpl">
{{each Hits}}
Page ${PAGENUMBER} - ${autn:summary} 
{{/each}}
</script>'

I can pull the PAGENUMBER tag out of the JSON but the template is not compiled correctly when i try and use autn:summary

How can I escape it?

I have tried \: and \\: and \3A but it complains about invalid characters.

Thanks

Upvotes: 0

Views: 534

Answers (2)

Brett Pontarelli
Brett Pontarelli

Reputation: 1728

Do I understand correctly that your data or a sub part of your data has a colon in the key? Then, if your data looks like this:

{
  "a:1": 1,
  "sub": [{
    "b:1": 'x'
  },{
    "b:1": 'y'
  }]
}

use the following in your template

${$data['a:1']}
{{each(i,s) sub}}
    ${s['b:1']}
{{/each}}

jsfiddle here: http://jsfiddle.net/brettwp/p9WUN/

Upvotes: 1

Nicola Peluchetti
Nicola Peluchetti

Reputation: 76880

Have you tried \\ (double backslash)?

for selectors you have to do that. Maybe it's the same in your case. Look here

Upvotes: 0

Related Questions