I was wondering if something like this would be possible, or some neat workaround.
I've got an foreach loop around a form and want the for attribute to have
the following value:
1st form: first_name
2nd form: first_name1
3rd form: first_name1
etc etc
<label data-bind="attr: {for: 'first_name' + ($index() + 1)}">
So i need to use something like this:
<label data-bind="attr: {for: 'first_name' + if(($index() != 0){($index() + 1)})}">
Obviously this isn't gonna work, so i was wondering if anyone has a clever way of achieving this.
You can use JavaScript ternary operator:
'first_name' + ($index() != 0 ? (''+($index() + 1)) : '')
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments