>我有一个列表,其中包含一个名为"状态日期"的日期时间列。我需要做的是在计算列中显示"状态日期"和 Now(( 之间的小时数和分钟数。 CONCATENATE 方法不起作用,因为它仅在编辑列表项时更新。我需要每次加载页面时更新时差。我正在使用解决方法在标签中利用 javascript。但是,当我尝试在新的 Date(( 方法中使用"状态日期"字段时,它返回为"1969 年 12 月 31 日星期三 19:00:43 EST " 下面是计算列的代码。它返回当前小时内的分钟数。
<img src='/_layouts/images/blank.gif' onload=""{var startTime=new Date("&[Status Date]&");var endTime=new Date();var difference=endTime.getTime()-startTime.getTime();var rawMins=1000*Math.round(difference/1000);mins= new Date(rawMins);this.parentNode.innerHTML= 'Minutes: '+ mins.getUTCMinutes() ;}"">
使用 JSLink 来满足此要求。
类似的线程在这里
<script type="text/javascript">
(function () {
'use strict';
var CustomReminder = {};
/**
* Initialization
*/
function init() {
CustomReminder.Templates = {};
CustomReminder.Templates.Fields = {
'Reminder': {
'View': customDTDisplay
}
};
// Register the custom template
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(CustomReminder);
}
function customDTDisplay(ctx) {
//from the context get the current item and it's value
if (ctx != null && ctx.CurrentItem != null) {
//your render logic
}
}
// Run our intiialization
init();
})();
</script>