使用把手使用JSON解析日期

时间:2016-02-01 06:41:00

标签: javascript jquery json asp.net-mvc handlebars.js

我正在学习一些.NET和using (DocX doc = DocX.Create(fileName)) { doc.PageLayout.Orientation = Orientation.Landscape; var table = doc.AddTable(12, 2); doc.InsertTable(table); doc.InsertSectionPageBreak(); } ,在这种情况下需要一些帮助来弄清楚如何处理handlebars日期解析:

我控制器中的方法

JSON

使用把手的模板

    public JsonResult stats()
    {
        IQueryable<EnrollmentDateGroup> data = from student in db.Students
             group student by student.EnrollmentDate into dateGroup
             select new EnrollmentDateGroup()
               {
                  EnrollmentDate = dateGroup.Key,
                  StudentCount = dateGroup.Count()
               };

        return Json(data.ToList());
    }

的JavaScript

        <script id="mytemplate" type="text/x-handlebars-template">
        <h3 style="margin-top:20px">Student Body Statistics</h3>
        <table>
            <tr>
                <th>Enrollment Date</th>
                <th>Students</th>
            </tr>
            {{#each this}}
            <tr>
                <td>{{{EnrollmentDate}}}</td>
                <td>{{{StudentCount}}}</td>
            </tr>
            {{/each}}
        </table>
    </script>

我的 <script type="text/javascript"> (function () { var templateHtml = $("#mytemplate").html(); var sourceHtml = Handlebars.compile(templateHtml); $.post("@Url.Action("stats")", "", function (data) { $('#stu').html(sourceHtml(data)); console.log(data); }, "json"); })(); </script> 结果数据是DB

的列表

如何将此日期解析为实际日期?

0 个答案:

没有答案