为什么相同的 JSON 对象代码生成带有ul
元素的输出,而不是带有table
标签的输出。
我有我的 Mustache 模板,例如:
<div id="template-ul">
<h3>{{name}}</h3>
<ul>
{{#students}}
<li>{{name}} - {{age}}</li>
{{/students}}
</ul>
</div>
<div id="template-table">
<table>
<thead>
<th>Name</th>
<th>Age</th>
</thead>
<tbody>
{{#students}}
<tr>
<td>{{name}}</td>
<td>{{age}}</td>
</tr>
{{/students}}
</tbody>
</table>
</div>
这是javascript代码:
var testing = {
"name" : "student-collection",
"students" : [
{
"name" : "John",
"age" : 23
},
{
"name" : "Mary",
"age" : 21
}
]
};
var divUl = document.getElementById("template-ul");
var divTable = document.getElementById("template-table");
divUl.innerHTML = Mustache.render(divUl.innerHTML, testing);
divTable.innerHTML = Mustache.render(divTable.innerHTML, testing);
这是 jsFiddle 上的代码 - http://jsfiddle.net/pRSjH/2/