我有一个Kendo列表视图,用于呈现listview具有日期字段的模板。我面临的问题是格式化模板上的输出,这是一个日期字段。我的模板是这样的:
<script type="text/x-kendo-tmpl" id="template">
#if(from_tx === '@User.Identity.Name')
{
#
<div class="chatmsg" >
<p style="word-wrap:break-word;">${msg_tx}</p>
<span class="timestamp">Sent: ${msg_dt}</span>
<span class="timestamp">Seen: ${seen_dt}</span>
</div>
#
}
else{
#
<div class="chatmsg sent">
<p style="word-wrap:break-word;">${msg_tx}</p>
<span class="timestamp">Recieved ${msg_dt}</span>
</div>
#
}#
</script>
我试过这个
#
<div class="chatmsg" >
<p style="word-wrap:break-word;"> "#= kendo.toString(${msg_dt}, 'MM/dd/yyyy') #"</p>
<span class="timestamp">Sent: ${msg_dt}</span>
<span class="timestamp">Seen: ${seen_dt}</span>
</div>
#
但是这段代码给了我一个模板错误..
任何人都可以帮我解决这个问题
答案 0 :(得分:4)
我认为你的msg_dt不是日期对象试试这个
<script type="text/x-kendo-tmpl" id="template">
<div class="chatmsg" >
<p style="word-wrap:break-word;"> "#= kendo.toString(kendo.parseDate(msg_dt, 'yyyy-MM-dd'), 'MM/dd/yyyy') #"</p>
<span class="timestamp">Sent: #= msg_dt #</span>
<span class="timestamp">Seen: #= seen_dt #</span>
</div>
</script>