Rip*_*ppo 3 format model-view-controller json date jtemplate
我有一个从MVC页面返回的以下JSON日期,例如
"DateProcessed":"\/Date(1258125238090)\/"
Run Code Online (Sandbox Code Playgroud)
我正在使用JTemplates处理数据,如下所示.
$('#result').setTemplate($("#TemplateResultsTable").html());
$("#result").processTemplate(data);
Run Code Online (Sandbox Code Playgroud)
这是我的结果模板
<script type="text/html" id="TemplateResultsTable">
<h3>{$T[0].StatusName} - Found: {$T.length} </h3>
<table>
<tr>
<th>Name</th>
<th>Description</th>
<th>Date Processed</th>
</tr>
{#foreach $T as match}
<tr>
<td>{$T.match.Title}</td>
<td>{$T.match.Description}</td>
<td>{$T.match.DateProcessed}</td>
</tr>
{#/for}
</table>
</script>
Run Code Online (Sandbox Code Playgroud)
除了我的日期在页面上输出为/ Date(1258125238090)/之外,一切都很棒
如何格式化结果模板中的日期?
如果有人搜索此帖子,请在下面回答...
添加以下JScript ....
function formatJSONDate(jsonDate) {
var date = eval(jsonDate.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
return dateFormat(date, "ddd ddS mmm yyyy");
}
Run Code Online (Sandbox Code Playgroud)
下载一个javascript 日期格式库,然后在你的jTemplate模板中添加
<td>{formatJSONDate($T.match.DateProcessed)}</td>
Run Code Online (Sandbox Code Playgroud)
就是这样!
| 归档时间: |
|
| 查看次数: |
1466 次 |
| 最近记录: |