【发布时间】:2011-03-20 22:21:30
【问题描述】:
我有这个多维 json,它应该生成一个 html 表。但截至目前,唯一要写入的内容是 tr,而不是 td。
我知道已经有一个类似的问题title,但用法完全不同。
与我所知道的不同之处在于,我正在使用模板方法编写模板,而不是将每个模板都声明为自己的脚本...
这是解析后的(JSON)数组
[
[
{
"name": "Morning meeting.",
"description": "The morning business meeting hosted at Apple.",
"image": "302632084.png",
"rating": "1.5",
"category": "4"
},
{
"name": "Winning",
"description": "",
"image": "321752348.png",
"rating": "5.0",
"category": "3"
},
{
"name": "1234566890abcdefghijklmnopqrstuvwxyz",
"description": "",
"image": "316892896.png",
"rating": "3.0",
"category": "16"
}
],
[
{
"name": "Kristian Lunch",
"description": "Having a lunch break.",
"image": "320196094.png",
"rating": "3.0",
"category": "8"
},
{
"name": "Dropping the kids off at the pool.",
"description": "A daly lesson on taking the kids to the pool.",
"image": "302658031.png",
"rating": "5.0",
"category": "4"
},
{
"name": "Dropping the kids off at the pool.",
"description": "A daly lesson on taking the kids to the pool.",
"image": "302658031.png",
"rating": "5.0",
"category": "4"
}
]
]
这是我应该写入数据的方法
EventsView.prototype.writeGrid = function(events)
{
var gridRows = "<td class='gridRow'>${name}</td>";
$.template("gridRows", gridRows);
var markup = "<tr class='gridCol'>{{events, gridRows}}</tr>";
$.template( "gridCols", markup );
$.tmpl( "gridCols", events )
.appendTo("#gridBody");
}
截至目前,这是生成的 html
<tbody id="gridBody">
<tr class="gridCol">
</tr>
<tr class="gridCol">
</tr>
</tbody>
这是我想要的 HTML...
<tbody id="gridBody">
<tr class="gridCol">
<td class="gridRow">Morning meeting.</td>
<td class="gridRow">Winning</td>
<td class="gridRow">1234566890abcdefghijklmnopqrstuvwxyz</td>
</tr>
<tr class="gridCol">
<td class="gridRow">Kristian Lunch</td>
<td class="gridRow">Dropping the kids off at the pool.</td>
<td class="gridRow">Dropping the kids off at the pool.</td>
</tr>
</tbody>
【问题讨论】:
标签: jquery multidimensional-array jquery-templates