【发布时间】:2015-05-05 00:48:53
【问题描述】:
问题:jQuery返回错误的HTML值
jQuery版本:jquery-1.10.2.min.js
由于某种原因,$("#peopleTemplate").html() 返回了错误的 HTML。
而不是返回,
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
{{#people}}
<tr>
<td>{{FirstName}}</td>
<td>{{LastName}}</td>
</tr>
{{/people}}
</tbody>
</table>
,jQuery 返回以下内容。
{{#people}}
{{/people}}
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody><tr>
<td>{{FirstName}}</td>
<td>{{LastName}}</td>
</tr></tbody>
</table>
我错过了什么?
这里是有问题的完整来源。
@using Demo.Javascript.Template.Hogan.Models
@model List<Person>
@{
ViewBag.Title = "People";
}
<h2>People</h2>
<div id="peopleTemplate" class="template">
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
{{#people}}
<tr>
<td>{{FirstName}}</td>
<td>{{LastName}}</td>
</tr>
{{/people}}
</tbody>
</table>
</div>
<div id="main"></div>
<script language="javascript">
debugger;
//var data = { "people" : @Html.Raw(Json.Encode(@Model)) };
var data = {
"people": [
{ "FirstName": "John", "LastName": "Doe" },
{ "FirstName": "Jane", "LastName": "Doe" },
{ "FirstName": "Robert", "LastName": "Smith" },
{ "FirstName": "Mike", "LastName": "Durden" },
{ "FirstName": "Marilin", "LastName": "Monroe" }
]
};
var template = Hogan.compile($("#peopleTemplate").html());
var rendered = template.render(data);
$("#main").html(rendered);
</script>
【问题讨论】:
标签: jquery asp.net-mvc hogan.js