-2

我有这样的事情:

<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属性?

4

2 回答 2

0

The problem was with my date representation. It was being a plain string, what I needed to do is to initialize new Date(date.replace(/(\d{2})\.(\d{2})\.(\d{4}) (\d{2}):(\d{2})/,'$3-$2-$1 $4:$5')).getTime()

于 2013-09-23T15:01:21.130 回答
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...

例外。如果您的日期是JSFiddle DEMO
,您 也应该使用date().getTime()observable

于 2013-09-23T14:49:09.000 回答