Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Model view controller JTemplates使用asp.net mvc格式化日期_Model View Controller_Json_Date_Format_Jtemplate - Fatal编程技术网

Model view controller JTemplates使用asp.net mvc格式化日期

Model view controller JTemplates使用asp.net mvc格式化日期,model-view-controller,json,date,format,jtemplate,Model View Controller,Json,Date,Format,Jtemplate,我从MVC页面返回了以下JSON日期,例如 "DateProcessed":"\/Date(1258125238090)\/" 我使用JTemplates处理数据,如下所示 $('#result').setTemplate($("#TemplateResultsTable").html()); $("#result").processTemplate(data); 这是我的结果模板 <script type="text/html" id="TemplateResultsTable"&g

我从MVC页面返回了以下JSON日期,例如

"DateProcessed":"\/Date(1258125238090)\/"
我使用JTemplates处理数据,如下所示

$('#result').setTemplate($("#TemplateResultsTable").html());
$("#result").processTemplate(data);
这是我的结果模板

<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>

{$T[0].StatusName}-找到:{$T.length}
名称
描述
处理日期
{#foreach$T作为匹配项}
{$T.match.Title}
{$T.match.Description}
{$T.match.DateProcessed}
{#/for}
除了我的日期作为/date(1258125238090)输出在页面上之外,所有这些都非常有用/


如何在我的结果模板中设置日期格式?

我遇到了同样的问题,结果(在非常恼怒之后)只是在JSON中以字符串形式返回日期。

请回答下面的问题,以防其他人搜索此帖子

添加以下JScript

function formatJSONDate(jsonDate) {
    var date = eval(jsonDate.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
    return dateFormat(date, "ddd ddS mmm yyyy");
 }  
下载javascript,然后在jTemplate模板中添加

<td>{formatJSONDate($T.match.DateProcessed)}</td>
{formatJSONDate($T.match.DateProcessed)}

就这样

看起来我已经弄明白了,当你得到正确的格式时很容易。。。。。将尽快发布答案感谢您花时间发布答案。刚刚帮我省了点活儿@除了使用
eval()
,Rippo没有其他方法可以解决这个问题吗?我从未找到过,但老实说,我不再使用JTemplates了。