12
我想,以产生一段JavaScript代码使用变量从我jsrender模板,但我无法弄清楚如何将一个<script type="text/javascript">
内我<script id="data-item-tpl" type="text/x-jsrender">
嵌入的脚本来jsrender模板
希望以下相当清楚。下面的代码产生一个。如果我从嵌入的脚本中删除标签,那么它就会以文本的形式直接打印到页面上。
在下面的代码,我想生成具有ID的DIV“chartId”,然后一个脚本,将填充内容DIV,通过MyChart对象。
<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>
有点哈克,但是,是的,它的工作原理!谢谢。 – Ina 2012-07-31 20:57:31
是的!这就是所有编写网络代码的人都必须经常生活的代码质量。 Web技术吸引。期。谢谢! – user2173353 2014-01-03 15:36:59
我在监视窗口中看到“太多非法字符”错误。我无法使用它。 – Shesha 2016-05-05 05:32:44