我想知道如何将json对象渲染为下划线模板:下面是我的json数据:
$('#testinfoWidget').testInfo({ // where testInfo is the jquery widget I created.
width: 300,
title: 'Test Info',
content:{name: 'test 2', status: 'FINISHED',region: 'Washington DC'}
});
我的HTML:
<div class="info loadtestinfo" id="testinfoWidget">
<ul class="contentBox boxHighlight" id = "contentBox"></ul></div>
我的underscore.js模板:
<script type = "test/javascript" id = "usageList">
`<li class="contentBoxHeader"><%- title %></li>`
`<li class="contentBoxContent">`
`<table class="simpleTable" id ="simpleTable">`
<tr>
<td class="label">Name:</td>
<td class="value"><%- content.name %></td>
</tr>
<tr>
<td class="label" style="vertical-align: top;">Status:</td>
<td class="value">
<span id="test_state"><%- content.status %></span>
</td>
</tr>
<tr>
<td class="label">Region:</td>
<td class="value"><%- content.region %></td>
</tr>
<tr>
<td class="label">Start:</td>
<td class="value"><%- content.start %></td>
</tr>
<tr>
<td class="label">End:</td>
<td class="value"><%- content.end %></td>
</tr>
</table>
</li>
我想使用上面的下划线模板并渲染o / p,如下所示:
Title: Test Info
Name: test2
Region: Washnigton DC
Status: FINISHED.
有没有人有任何想法???