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

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

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -