javascript のスニペットを生成するために、jsrender テンプレートの変数を使用したいのですが、変数<script type="text/javascript">
内にa を配置する方法がわかりません。<script id="data-item-tpl" type="text/x-jsrender">
うまくいけば、以下はかなり明確です。以下のコードは、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>