我正在尝试做一些非常简单的事情 - 在 jsRender 模板中测试来自 JSON 的布尔值。
JSON数据:
{ ...“CanAdd”:假,“CanDelete”:假,“CanEdit”:真,...}
模板:
{{if CanEdit === true}} 做点什么{{/if}}
生成的输出不显示“做某事”。JSON 数据中 CanEdit 的值为 true。我已经尝试过 CanEdit === "true"、CanEdit == true、CanEdit == "true",但没有任何效果。
我错过了什么?
编辑 这是我的完整模板:
<section class="ManagePageContentSection">
<h2>{{:PageTitle}} Page</h2>
{{for SectionContentList}}
<section class="PageSectionContent">
<h3>
{{:SectionName}} Section
{{if CanEdit === true}}
<span id="editPageSectionButton" class="editButton" title="Edit {{:SectionName}}">edit</span>
{{/if}}
{{if CanDelete === true}}
<span id="deletePageSectionButton" class="deleteButton" title="Delete {{:SectionName}}">delete</span>
{{/if}}
</h3>
{{if PageContentList.length > 0}}
<table class="PageContentTable">
<thead>
<tr>
<th>Order</th>
<th>Title</th>
<th>Subtitle</th>
<th>Summary</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{{for PageContentList}}
<tr id="{{:ContentId}}">
<td>{{:Ordinal}}</td>
<td>{{:Title}}</td>
<td>{{:SubTitle}}</td>
<td>{{:Summary}}</td>
<td>
{{if CanEdit}}
<span id="editPageSectionButton" class="editButton" title="Edit {{:Title}}">edit</span>
{{/if}}
{{if CanDelete}}
<span id="deletePageSectionButton" class="deleteButton" title="Delete {{:Title}}">delete</span>
{{/if}}
</td>
</tr>
{{/for}}
</tbody>
<tfoot>
</tfoot>
</table>
{{/if}}
</section>
{{/for}}
</section>
JSON
{
"AsOfDate": "/Date(1342800529826-0500)/",
"FullPageUrl": "/home/index",
"NavigationId": 7,
"NavigationName": "Home",
"PageContainerName": "ContentRenderedContainer",
"PageId": 2,
"PageName": "Home",
"PageTitle": "Home - Home",
"SectionContentList": [
{ … },
{ … }
],
"AddContentUrl": "",
"AddSectionUrl": "/PageSection/New/2",
"AdminTemplateName": "PageSectionContentTemplate",
"CanAdd": false,
"CanDelete": false,
"CanEdit": true,
"DeletSectioneUrl": "/PageSection/Delete",
"DeleteContentUrl": "",
"EditContentUrl": "",
"EditSectionUrl": "/PageSection/Edit"
}
模板正在呈现,除了 CanEdit、CandDelete 周围的逻辑。
我即将放弃做模板并返回在服务器上呈现 HTML。也许我正在做的事情太复杂了。也许模板应该只用于只读数据。
再次感谢你的帮助。