javascript - How do I store JSON data in an Underscore template? -


i store json object or string in underscore template.

<script id="report_field_template" type="text/template">     <div data-options="<%= options %>" role="<%- role %>" title="<%- title %>" class="ui-widget-content ui-corner-all report_field">         <p><%- field_text %></p>     </div> </script> 

the above not work if pass "options" json string or json object. ideas?

the trick use single quotes when dealing html5 data- attributes house json data:

<script id="report_field_template" type="text/template">     <div data-options='<%= options %>' role="<%- role %>" title="<%- title %>" class="ui-widget-content ui-corner-all report_field">         <p><%- field_text %></p>     </div> </script> 

notice single quotes around used hold value of data-options instead of double quotes.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

java - Using an Integer ArrayList in Android -