I'm going really mad for a thing:
var BoardNumber = Backbone.Model.extend({
defaults: function(){
return {
value: 0,
selected: false
};
},
toggle: function() {
this.save({selected: !this.get("selected")});
}
});
var BoardNumberView = Backbone.View.extend({
tagName: "li",
template: _.template('<div class="boardNumber"><p>{{value}}</p></div>'),
events: {
"click .boardNumber": "toggleDone",
"click .selected": "toggleDone"
},
initialize: function () {
this.listenTo(this.model, 'change', this.render);
},
render: function () {
this.$el.html(this.template(this.model.toJSON()));
return this;
},
toggleDone: function (evt) {
this.model.toggle();
}
});
var NumbersOnBoard = Backbone.Collection.extend({
model: BoardNumber,
toGenerate: 80,
url: "/numbers",
initialize: function(){
var i = this.toGenerate;
while(i--){
this.create({ value: this.toGenerate-i });
}
},
selected: function(){
return this.where({selected: true});
}
});
and nothing else should be necessary.. when I click on it, there is this error in the title, I don't really know what it can be
EDIT: Added collection and complete view. Note: the click launches the event this.render perfectly, and only then is lanunching the error and it's like the event listener from that model disappears.
EDIT #2: For the stack trace, In the development version of Backbone it shows:
triggerEvents backbone.js:205
Backbone.Events.trigger backbone.js:146
_.extend._onModelEvent backbone.js:933
triggerEvents backbone.js:206
Backbone.Events.trigger backbone.js:147
_.extend.set backbone.js:370