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 -

php - Boolean search on database with 5 million rows, very slow -

css - Text drops down with smaller window -