1

我需要根据 foreach 中的值附加一个动态类。

这是HTML:

<tbody data-bind="foreach: Tenancies">
    <tr data-bind="css: $parent.CurrentTenancy(date1, date2)">
        <td>blah</td>
    </tr>
</tbody>

这是JS:

self.CurrentTenancy = function(startDate, endDate) {
    var now = Models.Format.Date(new Date());

    if (now < startDate) {
        return "past";
    }

    if (now > endDate) {
        return "future";
    }

    return "current";
};

最后,我得到了 0 1 2 3 作为类的类属性。

4

0 回答 0