我有这样的事情:
<table data-bind="foreach: tuts" class="tutorsTable">
(...) //here it sees my model
<!-- ko if: date.getTime() > (new Date().getTime() - 900000) -->
<tr>
<td colspan="2" class="center">
<a data-bind="attr: { href: 'https://mypage.com/videoconference/talk/' + peer + '/1/1/0'}, text: 'Start!'"></a>//this is being rendered as is
</td>
</tr>
<!-- /ko -->
</table>
为什么它会按原样在if
语句中呈现代码,而不是执行data-bind
属性呢?
答案 0 :(得分:0)
您应该在<!-- ko if -->
标记
<tr>
<table data-bind="foreach: tuts" class="tutorsTable">
<tr>
<!-- ko if: date.getTime() > (new Date().getTime() - 900000) -->
<td colspan="2" class="center">
<a data-bind="attr: { href: 'https://mypage.com/videoconference/talk/' + peer + '/1/1/0'}, text: 'Start!'"></a>//this is being rendered as is
</td>
<!-- /ko -->
</tr>
</table>
否则你会得到
Uncaught Error: Cannot find closing comment tag to match <!- ko...
异常。
如果您的日期为date().getTime()
,则还应使用observable
JSFiddle DEMO
答案 1 :(得分:0)
问题在于我的日期表示。它是一个简单的字符串,我需要做的是初始化new Date(date.replace(/(\d{2})\.(\d{2})\.(\d{4}) (\d{2}):(\d{2})/,'$3-$2-$1 $4:$5')).getTime()