【发布时间】:2016-09-20 08:03:55
【问题描述】:
我有以下 columnDefs
self.columnDefs = [
{ width: 150, field: 'timeReceived', displayName: 'Time Received', cellFilter: function (data) { return moment(data).format('DD/MM/YYYY h:mm a') } },
{ width: 500, field: 'name', displayName: 'Name' },
{ width: 150, field: 'LinkToTimeSent', displayName: 'Time SentX', cellTemplate: '<a data-bind="text:$parent.entity.timeSent, attr: { href: $parent.entity.linkToTimeSent}" ></a>' },
];
我的问题在于 Time SentX。我希望它显示 entity.timeSent 的内容,但使用时刻库转换为人类消费。
如何从我的 columnDefs 中调用函数 moment($parent.entity.timeSent).format('DD/MM/YYYY h:mm a')?
在下面的 plunk 中,第 96 行需要包含类似
text:moment($parent.entity.TimeSent, "DD/MM/YYYY h:mm a") but I can't get it to work!
【问题讨论】:
-
在您的问题中使用 cellFilter 有什么问题:
{ field: 'TimeSent', displayName: 'TimeSent', width: 130, cellFilter: function (data) { return moment(data).format('DD/MM/YYYY h:mm a')} },工作正常:plnkr.co/edit/sqNyTmm4ZisVg1CzVSIt?p=preview -
嗨@nemesv,我希望单元格中的文本成为超链接。因此,它应该显示发送的时间,但是当用户单击它时,导航到已发送消息的副本。这就是为什么我使用 cellTemplate 而不是 cellFilter
标签: javascript knockout.js kogrid