backbone.js iterate a collection -


i have set collection logs. api returns results json. saw previous topic suggested add parse method on collection. having done so, when execute code not getting output console. nevertheless, new backbone insight and/or guidance appreciated. understanding of collection.each may not correct.

var log = backbone.model.extend({});  var loglist = backbone.collection.extend({     model:  log,     url:    'api/logs',     parse:  function(response) {         return response.logs;     } });  var loglistview = backbone.view.extend({      el: $('#logs-list'),      initialize: function() {         this.collection = new loglist();         this.collection.fetch();         this.render();     },     render: function() {         this.collection.each(function(log) {             console.log('log item.', log);         });     } });  $(document).ready(function(){     console.log('ready.');     new loglistview(); }); 

fetch asynchronous. rewrite code call render callback:

var loglistview = backbone.view.extend({  el: $('#logs-list'),  initialize: function() {     var self = this;     this.collection = new loglist();     this.collection.fetch().done(function(){       self.render();     });  }, render: function() {     this.collection.each(function(log) {         console.log('log item.', log);     }); } });  

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -