5

我正在尝试DateTime在我的 Kendo ListView 模板中格式化我的对象,但建议的kendo.toString方法似乎对我不起作用。

我已经删除了很多与我的问题无关的代码,以使其更易于理解。

我有一个Kendo DataSource如下所示:

contactDataSource: new kendo.data.DataSource({
    transport: {
        read: {
            url: "/baa/contact/getcontacts",
            dataType: "json",
            type: "GET"
        }
     },
     schema: {
        model: {
            id: "Id",
            fields: {
                Id: { type: "number", editable: false, nullable: true },
                CompanyName: { type: "string" },
                ContactName: { type: "string" },
                ContactPhone: { type: "string" },
                ContactEmail: { type: "string" },
                ImageUrl: { type: "string" },
                Website: { type: "string" },
                RecentBaas: [
                    {
                        Name: { type: "string" },
                        StatusDisplay: { type: "string" },
                        Status: { type: "number" },
                        LastModDate: { type: "date" }
                    }
                ]
            }
        }
    }
})

然后我的视图上有一个模板,如下所示:

<script type="text/x-kendo-templ" id="contactTemplate">
    <div class="row">
        <div class="col-md-12">
            # for (var i = 0; i < RecentBaas.length; i++) { #
            # if (RecentBaas[i].Status == 1) { #
                <div class="alert alert-success" role="alert">
                    <p>#=kendo.toString(RecentBaas[i].LastModDate, "F")#</p>
                </div>
            # } #
            # } #
        </div>
    </div>
</script>

加载此页面时,我的控制台中没有任何错误,但日期根本没有格式化。它仍然只是显示/Date(1461203814927)/例如。

我已经阅读了关于如何使用该toString函数来格式化DateTime对象的 Kendo 文档,并且据我所知,我所做的一切都是正确的。但也许我仍然缺少一些东西?

4

1 回答 1

10

请尝试使用以下代码片段。

<script type="text/x-kendo-templ" id="contactTemplate">
    <div class="row">
        <div class="col-md-12">
            # for (var i = 0; i < RecentBaas.length; i++) { #
            # if (RecentBaas[i].Status == 1) { #
                <div class="alert alert-success" role="alert"> <p>#=kendo.toString(kendo.parseDate(RecentBaas[i].LastModDate), 'yyyy-MM-dd')#</p>
                </div>
            # } #
            # } #
        </div>
    </div>
</script>

让我知道它是否不起作用

于 2016-08-03T16:32:27.633 回答