1
我有这应该生成一个HTML表的多维JSON。但就目前而言,唯一被写入的东西是tr,没有td。JSON与jQuery模板
我知道那里已经有类似的问题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>
我我正在使用json .... – Peter 2011-03-20 23:00:07
你使用json2.js吗?如果是这样,你可以请一个jsFiddle,我会为你找找吗?我很高兴能够帮助解决这个问题,不久前我做了一个类似的模板系统... :-) – Mitch 2011-03-20 23:34:58
我不太确定我使用的是什么json。我把它贴在jsfiddle上..感谢您的帮助! http://jsfiddle.net/YHQAa/ – Peter 2011-03-21 00:07:58