Questions tagged [backbone-events]

This is for backbone.js questions that specifically relate to Backbone's event handling system.

Docs

787 questions
11
votes
1 answer

How to add a default error handler to all Backbone models?

Background: Backbone model provides an option to register a fallback error handler that will be called each time a call to the server fails and no specific handler is provided. MyModel = new Backbone.Model.extend({ initialize: function(option) { …
Dana Shalev
  • 1,894
  • 1
  • 13
  • 13
10
votes
2 answers

Avoid event.preventDefault() boilerplate in backbone event handlers

I have a lot of Backbone.js actions that start with link like: Make Cookies and a Backbone.View events hash like: 'click [href=#makeCookies]': 'makeCookies' and an event handler function like: makeCookies: function…
Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
10
votes
3 answers

Backbone.js - Both click and double click event getting fired on an element

In my Backbone View, I have defined events like this: events : { 'click .elm' : 'select', 'dblclick .elm' : 'toggle' }, select: function(e){ e.preventDefault(); console.log('single clicked'); } toggle : function(e){ …
Veera
  • 32,532
  • 36
  • 98
  • 137
9
votes
1 answer

Backbone: How to update a collection view when collection changes?

I'm relatively new to Backbone.js. I'm initializing a collection view and passing in a collection at creation time. suggestionsView = new TreeCategoriesAutoSuggest.Views.Suggestions({ collection: new…
Alex B
  • 1,009
  • 3
  • 18
  • 26
8
votes
2 answers

Events in Backbone.js nested views

I have a view called DashboardView that instantiates multiple WidgetViews. Each widget needs to have its own event bindings. So far as I can tell, these bindings get lost when the view is rendered and added to the parent view, i.e.: class…
picardo
  • 24,530
  • 33
  • 104
  • 151
8
votes
3 answers

Overwriting a Backbone Models Change Event

I think what I want to do is pretty simple I just don't know how to do it. I would like to fire my own event when one of my models attributes changes for the purpose of passing some data to the event handler (whether the change was an increase or…
Matthew
  • 12,892
  • 6
  • 42
  • 45
8
votes
1 answer

Can't get Backbone routes without hashes?

I want to have bookmarkable URLs that the browser can capture and handle. If I just use Backbone.history.start(), then I can use hash URLs, like /#accounts. But I want URLs without the hashes, a la /accounts. But I can't get this to work using…
Nutritioustim
  • 2,686
  • 4
  • 32
  • 57
8
votes
2 answers

Backbone.js views delegateEvents do not get bound (sometimes)

I'm using Backbone.js and sometimes the views events do not get bound correctly. I can check the event binding situation with $(viewselector).data() in jQuery. Most of the time there are events, sometimes there aren't! Are there any known things I…
FriiSource
  • 321
  • 2
  • 6
  • 12
8
votes
1 answer

Binding Backbone change event to attribute of model in a collection

I have a view that takes a collection like below: MyView = Backbone.View.extend({ initialize: function() { this.collection.on("change://an attribute of a model in aCollectionToRender", someAction); } }); var MyViewInstance = new…
Jay
  • 3,471
  • 4
  • 35
  • 49
8
votes
2 answers

Backbone - Why doesn't a collection.reset trigger a model event?

I'm curious to find out why resetting a backbone collection doesn't fire a model event. However, it seems only logical to fire a model event when a model is physically being removed from a collection. Is this intentional or am I missing something?…
8
votes
2 answers

Event fires twice

I'm declaring a View like this: var VirtualFileSelectorView = Backbone.View.extend({ selected: function() { console.log("selected function"); }, initialize: function() { // Shorthand for the application namespace …
marcus
  • 9,616
  • 9
  • 58
  • 108
7
votes
3 answers

backbone view events don't work after re-render

I'm pulling my hair out, I cannot seem to get mouse events to work on my backbone view after the view is re-rendered unless i do the most ridiculous thing: $("a").die().unbind().live("mousedown",this.switchtabs); I actually had this in there but…
Alex
  • 3,732
  • 5
  • 37
  • 59
7
votes
1 answer

Getting changed attribute on change event

In this global change event, is there a way I can detect which attribute was changed? myModel.on('change', function(model) { // Which attribute changed? }); I tried the following: Using myModel.previousAttributes() but it always returned latest…
jviotti
  • 17,881
  • 26
  • 89
  • 148
7
votes
1 answer

How to prevent backbone model to collection event propagation?

How do I prevent Backbone Model events from propagating to Backbone Collections? Edit: Let's say I have something like the following, where CollectionView contains a collection of MyModels... var CollectionView = Backbone.Collection.Extend({ …
user1031947
  • 6,294
  • 16
  • 55
  • 88
7
votes
2 answers

"Uncaught TypeError: Object [object Object] has no method 'off'" error using events when moved to backbone 0.9.10

I has a view with this event: var View = Backbone.View.extend({ el: $('#test'), events: { "change input": "test" }, test: function(e) { console.log("test"); } }); var view = new View(); With backbone 0.9.9 it work, but with…
Camilo
  • 2,844
  • 2
  • 29
  • 44
1 2
3
52 53