javascript - Uncaught TypeError: Object [object Window] has no method 'each' function -


hey guys here js file , taking error message each function @ line:24 , not know why couldnt find whats wrong. trying see list of items on console.log panel not give me list on html page.

(function() {      window.app = {          models: {},         collections: {},         views: {}     };      window.template = function(id){         return _.template( $('#' + id).html() );     };  app.models.task = backbone.model.extend({});  app.collections.task = backbone.collection.extend({     model: app.models.task });  app.views.tasks = backbone.view.extend({     tagname: 'ul',      render: function(){         this.collection.each( this.addone, this);          return this;     },      addone: function(task){         //creating new child view         var taskview = new app.views.task({ model: task });          //append root element         this.$el.append(taskview.render().el);     } });  app.views.task = backbone.view.extend({     tagname: 'li',      template: template('tasktemplate'),      events: {         'click .edit': 'edittask'     },      edittask: function(){         alert('you editing tas.');     },      render: function(){         var template = this.template( this.model.tojson() );         this.$el.html(template);         return this;     }  });   var taskscollection = new app.views.task([ {     title: 'go store',     priority: 4 }, {     title: 'go mall',     priority: 3 }, {     title: 'get work',     priority: 5 } ]);  var tasksview = new app.views.tasks({ collection: taskscollection });  $('.tasks').html(tasksview.render().el);  })(); 

you're creating view instance though class:

app.views.tasks = backbone.view.extend({ /* ... */ });  var taskscollection = new app.views.task([ {     title: 'go store',     priority: 4 }, //... 

and create instance of view , hand taskscollection though collection:

var tasksview = new app.views.tasks({ collection: taskscollection }); 

but views , collections different things , collection's have each method (unless add each view of course).

you want create taskscollection app.collections.task:

var taskscollection = new app.collections.task([ {     title: 'go store',     priority: 4 }, //... 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -