【发布时间】:2012-07-27 13:58:19
【问题描述】:
我想使用我的 jsrender 模板中的一个变量来生成 javascript 的 sn-p,但我不知道如何在我的 <script id="data-item-tpl" type="text/x-jsrender"> 中放置一个 <script type="text/javascript">
希望以下内容相当清楚。下面的代码产生一个Uncaught SyntaxError。如果我从嵌入脚本中删除标签,那么它只是作为文本打印到页面上。
在下面的代码中,我试图生成一个 id 为“chartId”的 div,然后是一个脚本,该脚本将通过 MyChart 对象用内容填充该 div。
<script id="data-item-tpl" type="text/x-jsrender">
<div class="item">
<div class="graphs">
<ul class="thumbnails">
{{for graphs}}
<li><div class="thumbnail"><img src="{{html:url}}" width="190" height="120" /><p>{{html:graphTitle}}<br />{{html:value}}</p></div></li>
{{/for}}
<!-- Here we insert both the placeholder for, and the javascript to populate charts -->
<li><div id="{{html:chartId}}" style="width:120;height:190px;"></div></li>
<script type="text/javascript">
var chartObj = new MyChart("{{html:chartId}}");
chartObj.render();
</script>
</ul>
</div>
...
</script>
【问题讨论】:
标签: javascript jsrender