Qui*_*ver 4 telerik telerik-grid kendo-ui kendo-grid kendo-template
我正在尝试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" }
}
]
}
}
}
})
Run Code Online (Sandbox Code Playgroud)
然后我在我的视图上有一个模板,如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
我加载此页面时,我的控制台中没有出现任何错误,但日期根本没有格式化.它仍然只是作为/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>
Run Code Online (Sandbox Code Playgroud)
如果它不起作用,请告诉我