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
Post a Comment