Kendo UI loop through collection in Json within template for ListView Kendo UI loop through collection in Json within template for ListView json json

Kendo UI loop through collection in Json within template for ListView


You can do this with a counter in the for-loop. This should fix your issue:

<script type="text/x-kendo-tmpl" id="template">    <div class="subscriberFunction">        <h3>${Title}</h3>        <!-- Display KeyPairs -->        <ul>            #for (var i=0,len=KeyPairs.length; i<len; i++){#                <li>${ KeyPairs[i] }</li>            # } #        </ul>    </div></script>


You can have arbitrary JavaScript code inside a template:

<script type="text/x-kendo-tmpl" id="template">    <div class="subscriberFunction">        <h3>${Title}</h3>       <!-- Display KeyPairs -->         <ul>         # for (var key in KeyPairs) { #              <li>${ KeyPairs[key] }</li>         # } #         </ul>    </div></script>


It is possible to loop through the collection once you know the syntax. This is basically Stans answer with clearer syntax.If you're using a List you can access properties just by adding them, e.g., <li>#=KeyPairs[i].FooBar#</li>

<script type="text/x-kendo-tmpl" id="template">    <div class="subscriberFunction">    <h3>#=Title#</h3>    <ul>        # for (var i = 0; i < KeyPairs.length; i++) { #            <li>#=KeyPairs[i]#</li>        # } #    </ul></div>