A
A
aumarov2014-05-12 12:40:22
JavaScript
aumarov, 2014-05-12 12:40:22

Underscore doesn't work correctly, what should I do?

I use a template engine, I send an ajax request, what is needed is returned in the network tab, but underscore inserts a lot of elements, although they returned, let's say only 2. The same template code used to work on another site, I just copied it and pasted it, of course, having corrected.
ajax code

$(".sended-param").click(function(){
  var template = $("#products").html();
  $(this).find("input[type=radio]").prop('checked', true);

  $.ajax({
    type: "post",
    url: "/filter",
    data: $(".filter form").serialize(),
    success: function(result) {
            $(".products").html(_.template(template,{ result:result }));
        }
  });
});

Template code
<script type="foo/bar" id="products">
<% _.each(result,function(item,key,list){ %>
    <li>BLa</li>
<% }); %>
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-05-12
@aumarov

Wang mode: check what you are passing to templates.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question