This is for backbone.js questions that specifically relate to Backbone's event handling system.
Questions tagged [backbone-events]
787 questions
117
votes
15 answers
Backbone View: Inherit and extend events from parent
Backbone's documentation states:
The events property may also be defined as a function that returns an events hash, to make it easier to programmatically define your events, as well as inherit them from parent views.
How do you inherit a parent's…

brent
- 1,709
- 2
- 13
- 15
85
votes
7 answers
Destroy or remove a view in Backbone.js
I'm currently trying to implement a destroy/remove method for views but I can't get a generic solution to work for all my views.
I was hoping there would be an event to attach to the controller, so that when a new request comes through it destroys…

Ad Taylor
- 2,775
- 5
- 27
- 32
55
votes
2 answers
Backbone 0.9.9: Difference between listenTo and on
I am trying to learn the new changes they did in Backbone 0.9.9.
Currently I got problems to understand the difference between listenTo and on:
listenTo
var View = Backbone.View.extend({
tagName: "div",
intialize: function() {
…

bodokaiser
- 15,122
- 22
- 97
- 140
45
votes
7 answers
Backbone JS: can one view trigger updates in other views?
In my simple project I have 2 views - a line item view (Brand) and App. I have attached function that allows selecting multiple items:
var BrandView = Backbone.View.extend({
...some code...
toggle_select: function() {
…

mvbl fst
- 5,213
- 8
- 42
- 59
38
votes
3 answers
Backbone: event lost in re-render
I have super-View who is in charge of rendering sub-Views. When I re-render the super-View all the events in the sub-Views are lost.
This is an example:
var SubView = Backbone.View.extend({
events: {
"click": "click"
},
click:…

fguillen
- 36,125
- 23
- 149
- 210
30
votes
2 answers
delegateEvents in backbone.js
Can anyone please explain me what delegateEvents in backbone.js does? The documentation did not help me to understand.
My exact use case is:
I have a main view X with an inner view Y. They work great, but if I go to main view Z and then go back to X…

Yaron Naveh
- 23,560
- 32
- 103
- 158
28
votes
3 answers
Binding multiple event types in backbone views
I was wondering if it is possible to bind multiple event types in backbone within a single line.
Consider the following:
var MyView = Backbone.View.extend({
id: 'foo',
events: {
'click .bar': 'doSomething',
'touchstart .bar':…

stephenmuss
- 2,445
- 2
- 20
- 29
26
votes
2 answers
In Backbone.js, why do silent changes trigger change events eventually?
When I pass {"silent":true} while setting an attribute in a Backbone model, why doesn't that just suppress the change:attribute event? What is the advantage of firing that event the next time an attribute is changed?
Update
Backbone 0.9.10 changed…

stinkycheeseman
- 43,437
- 7
- 30
- 49
25
votes
2 answers
Backbone model.destroy(): Is explicit removal from collection necessary?
I have a simple question. I am looking at a function with 2 lines of code:
deleteTask: function() {
this.parent.collection.remove(this.model);
this.model.destroy();
}
If I comment out the first line, which is supposed to remove the model…

AndraD
- 2,830
- 6
- 38
- 48
25
votes
2 answers
How can I attach 2 handlers to the same event?
I can attach handlers to Backbone Views like:
var TodoView = Backbone.View.extend({
events: {
"xxx": "eventHandler1"
"yyy": "eventHandler2"
}
});
But what if I want to attach more than 1 handler to the same event?
var…

jm2
- 763
- 2
- 13
- 27
23
votes
2 answers
Why is this sinon spy not being called when I run this test?
I have a Backbone Model:
class DateTimeSelector extends Backbone.Model
initialize: ->
@bind 'change:date', @updateDatetime
@bind 'change:time', @updateDatetime
updateDatetime: =>
# do some stuff with the sate and time
And I have…

David Tuite
- 22,258
- 25
- 106
- 176
23
votes
2 answers
Correct way of binding multiple attribute changes to a Backbone.js model
I have the following code, where I bind a change to a single attribute "attribute_1".
var Mine = Backbone.Model.extend({
initialize: function() {
this.bind("change:attribute_1", function() {
console.log('changed!');
});
}
});
How…

ericbae
- 9,604
- 25
- 75
- 108
20
votes
3 answers
Backbone.js listenTo window resize throwing [object Object] has no method 'apply' error
Problem:
I'm trying to attach a resize event to the window from a view using the new listenTo() method in Backbone.js. The event seems to bind to the window, however, when the window is actually resied the following error is thrown:
Uncaught…

Zengineer
- 528
- 2
- 7
- 20
20
votes
3 answers
Backbone trigger two methods in one event
I am using Backbone and I have a view with events defined:
....
events: {
'click .search-button': 'setModelTerm',
'change .source-select': 'setModelSourceId',
'change .source-select': 'activateSource'
},
…

Naor
- 23,465
- 48
- 152
- 268
19
votes
1 answer
Backbone View events not firing
I am using Rails3 as my backend and Jammit to asset... Now I am trying to not compress and even package the assets.
The simple event don't get run, but the alert('asd') int initialize is working as expected.
I have already tried other kinds of…

pedrofs
- 612
- 1
- 6
- 14