在Kendo模板中格式化日期
问题描述:
我想在我的Kendo ListView模板中格式化DateTime
对象,但建议的kendo.toString
方法似乎不适用于我。在Kendo模板中格式化日期
我已经剪出了很多与我的问题无关的代码,使它更容易理解。
我有一个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文档,并且据我所知我做的都是正确的。但也许我仍然失去了一些东西?
答
请试试下面的代码片段。
<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>
让我知道,如果它不工作
没错奏效!我不认为我必须先解析它,因为我可以发誓我之前没有解析过。虽然谢谢! – Quiver