0
obj {column1{name:abc, items{price:10, count:5}, title:def}}

I have an object as above, the count has been added after an loop ajax succession to the object obj, I will then append the obj to the underscore template.

I did a console.log of the obj after adding count into the obj and it appears to be there. When I do a loop of items in the template, count seems to be missing. I did another console.log of items in the template and count is appears to be there.

Anyone knows the mystery of count?

$.each(rows, function(i, row) {
    $.each(row.items, function(i, item) {
        $.ajax({
            url: 'route',
            data: { data: datapost },
            type: 'GET',
            success: function(num){
                item.count = num;
            }
        });
    });
});
$('#container').append(template(row));

the missing count in the template:

<% _.each(items, function(item) { %>
    <%= item.price %> <%= item.count %>
<%})%>
vinz
  • 350
  • 2
  • 9
  • 19
  • I'm afraid it will remain a mystery unless you show some example code that replicates the problem. – JJJ May 04 '15 at 20:20
  • @Juhana i apologize, just did an edit. – vinz May 04 '15 at 20:24
  • I'm a bit confused; you're making an async call, but the code that doesn't work is sync? I mean, you need to wait for the call to complete before you start using data added in the callback. – Dave Newton May 04 '15 at 20:27
  • @DaveNewton thanks mate, i understand how it works now. will be editing my codes – vinz May 04 '15 at 21:13

0 Answers0