javascript - Split arrays from object and use in underscore template -
below response server using $.getjson. want able call each array separately can use underscore js template output data.
how can split arrays out or call each array separately perform necessary loop show both kept , passed data?
{ kept: [ 0: { counter: "1", image: "image1.png", name: "alias" }, 1: { counter: "1", image: "image2.png", name: "lorem" } ], passed: [ 0: { counter: "1", image: "image3.png", name: ""dolores"" }, 1: { counter: "1" image: "image4.png" name: ""quisquam"" } ] }
you can kept , passed in template because these object properties, this
<script type="text/template" id="tpl"> <h1>kept</h1> <% _.each(data.kept, function(el) { %> <p><%= el.name %></p> <p><%= el.image %></p> <p><%= el.name %></p> <% }); %> <h1>passed</h1> <% _.each(data.passed, function(el) { %> <p><%= el.counter %></p> <p><%= el.image %></p> <p><%= el.name %></p> <% }); %> </script> _.template($('#tpl').html(), {data: data})
Comments
Post a Comment