Note that there are some explanatory texts on larger screens.

plurals
  1. POUncaught TypeError: Cannot call method 'on' of undefined - Backbone.js
    primarykey
    data
    text
    <p>I'm having some error in my app and don't know why.</p> <pre><code>Uncaught TypeError: Cannot call method 'on' of undefined </code></pre> <p>It happens on my collection view, follow the code:</p> <pre><code>App.WorkoutsView = Backbone.View.extend({ initialize: function(){ this.collection.on('add', this.addOne, this); this.collection.on('reset', this.addAll, this); }, render: function() { this.addAll(); return this; }, addAll: function() { this.$el.empty(); this.collection.forEach(this.addOne, this); }, addOne: function(Workout) { var workoutView = new App.WorkoutView({model: App.Workout}); this.$el.append(workoutView.render().el); } }); </code></pre> <p>the problem is on:</p> <pre><code>this.collection.on('add', this.addOne, this); </code></pre> <p>Anyone knows why?</p> <p>** Edit: Collection code **</p> <pre><code>App.WorkoutItems = Backbone.Collection.extend({ model: App.Workout, url: '/workouts', localStorage: function() {new Backbone.LocalStorage('Workout')}, initialize: function() { this.on('remove', this.hideWorkout, this); }, hideWorkout: function() { model.trigger('hide'); }, focusOnWorkoutItem: function() { var modelsToRemove = this.filter(function(workoutItem) { return workoutItem.id != id; }); this.remove(modelsToRemove); } }); </code></pre> <p><strong>Edit: my Router code where i'm instantiating WorkoutsView:</strong></p> <pre><code>App.Router = Backbone.Router.extend({ routes: { '':'index' }, initialize: function() { this.workoutItems = new App.WorkoutItems(); this.workoutsView = new App.WorkoutsView(); this.workoutsView.render(); }, index: function() { $('#workouts').html(this.workoutsView.el); this.workoutsItem.fetch(); } }); new App.Router; Backbone.history.start(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload