I am new to KO, in my html file I am printing a value like this -
<!-- ko foreach: { data: JSON.parse($parent.options), as: 'option' } -->
<!-- ko if: option.label === 'AAA' || option.label === 'BBB' -->
<dd class="values" data-bind="html: option.value"></dd>
<!-- /ko -->
<!-- /ko -->
And its working fine . But what I want is, I want assign all values of loop to a variable and want to print after loop. Like we do in php-
foreach($data as $key=> $index){
if($key==0)
$var = $index['value'];
else
$var .= ' '.$index['value'];
}
echo $var
Want to do the same in KO's html file using above KO loop.
Please help me in this.
Thanks
Vivek Kumar
5,7932 gold badges26 silver badges55 bronze badges
asked Feb 27, 2019 at 15:04
Atul
9152 gold badges15 silver badges36 bronze badges
1 Answer 1
You can use ifnot binding to accomplish this as follows ;
<!-- ko foreach: { data: JSON.parse($parent.options), as: 'option' } -->
<!-- ko if: option.label === 'AAA' || option.label === 'BBB' -->
<dd class="values" data-bind="html: option.value"></dd>
<!-- /ko -->
<!-- ko ifnot: option.label === 'AAA' || option.label === 'BBB' -->
<dd class="values" data-bind="html: ' ' + option.value"></dd>
<!-- /ko -->
<!-- /ko -->
answered Jun 21, 2019 at 7:09
Vivek Kumar
5,7932 gold badges26 silver badges55 bronze badges
default