Wesley Skeen
Wesley Skeen

Reputation: 1214

Conditional statement embedded in data-bind

I'm binding table rows using foreach statement. The row HTML markup is:

<tr data-bind="css: 'new-row', rowClick: $parent.editCost">

I would like to do something like this:

<tr data-bind="css: 'new-row', if: $index() > 0 {rowClick: $parent.editCost} ">

Is something like this possible?

Upvotes: 2

Views: 891

Answers (1)

Damien
Damien

Reputation: 8987

Of course, you can do it :

<tr data-bind="click: function(){ if($index() > 0) $parent.editCost($data);} ">

If rowClick is a cutom binding, you can do that :

<!-- ko id : $index() == 0 -->
<tr data-bind="css: 'new-row'>
<!-- /ko -->
<!-- ko id : $index() > 0 -->
<tr data-bind="css: 'new-row', rowClick: $parent.editCost">
<!-- /ko -->

I hope it helps.

Upvotes: 4

Related Questions