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

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -