arrays - knockout foreach add row number to grid -
i have grid fills array within array. creates according 1 array , fills column array.
<div id="formula" data-bind="with:currentformula"> <!-- ko foreach:$parent.tones--> <div class="col-sm-2" data-bind="foreach:$parents[1].levels"> <a href="#" class="thumbnail img-responsive" data-bind="click: $root.hascurrent() ? $root.currentformula().setending.bind($index(),$parentcontext.$index()) : $root.currentformula().setstarting.bind($index(),$parentcontext.$index())"> <img data-bind="attr:{ src: '/content/images/colors/' + $index() + $parentcontext.$index() + '.png' }" alt="" /> </a> </div> <!-- /ko--> </div>
what need create new column before col 1 , add $index() + 1, or row number work column.
i've looked on , have not found works.
how this?
from can tell, rows being created based on currentformula.tones
within <!-- ko foreach:$parent.tones-->
, columns based on tones.levels
. should create div
binds text $index() + 1
if first level
(column). this, need move loop creating columns above div
represent column.
something this:
<div id="formula" data-bind="with: currentformula"> <!-- ko foreach:$parent.tones--> <!-- ko foreach:$parents[1].levels --> <!-- if first level/column, create new column show rownum --> <div class="col-sm-2" data-bind="if: $index() == 0, text: 'row ' + $parent.$index() + 1"></div> <!-- normal column creation --> <div class="col-sm-2" > <a href="#" class="thumbnail img-responsive" data-bind="click: $root.hascurrent() ? $root.currentformula().setending.bind($index(), $parentcontext.$index()) : $root.currentformula().setstarting.bind($index(), $parentcontext.$index())"> <img data-bind="attr: { src: '/content/images/colors/' + $index() + $parentcontext.$index() + '.png' }" alt="" /> </a> </div> <!-- /ko--> <!-- /ko--> </div>
Comments
Post a Comment