Knockout ‘for’ binding?



  • 3 Answer(s)

        The Repeat binding will do all the required things for this .

    <tbody>
        <tr data-bind="repeat: { foreach: selectedTab().runners, index: '$runner' }">
            <td>
                <div class="a-i-post"></div>
            </td>
            <td data-bind="repeat: selectedTab().races">
                <!-- ko if: $item().Runners.length > $runner -->
                <input type="checkbox" />
                <!-- /ko -->
            </td>
        </tr>
    </tbody>
    
    Answered on January 2, 2019.
    Add Comment

        Use this code for this .

    <div data-bind="foreach: [0,0,0,0,0]">
        <span data-bind="text: $index"></span>
    </div>
    

        And the user will  get elements 0-4.

    Answered on January 2, 2019.
    Add Comment

        Make an Array object for this :

    <!-- ko foreach: new Array(the_length_you_need) -->
        <span>★</span>
    <!-- /ko -->
    

        Then a star is print  for the_length_you_need times .

    Answered on January 2, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.