Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to attach event to <body> using backbone.js?

Is it possible? Something like this:

...
events {
  'keydown body' : 'doSmth'
}
...
like image 234
sdespolit Avatar asked Dec 15 '11 07:12

sdespolit


People also ask

How do you trigger an event in the Backbone?

Backbone. js trigger Event is used to invoke or callback the function for the given event or a space-delimited list of events. The subsequent arguments will be passed along to the event callbacks in order to trigger it.

Is Backbone JS still used?

Backbone. Backbone has been around for a long time, but it's still under steady and regular development. It's a good choice if you want a flexible JavaScript framework with a simple model for representing data and getting it into views.

Is Backbone JS frontend or backend?

Backend Synchronization BackboneJS is use with the front-end and back-end systems, allows the synchronization with the backend to provide support to RESTful APIs.


1 Answers

This is not possible because Backbone uses the events hash to subscribe to events on the view's element (view.el property) and the element's descendants. It does not subscribe to events from elements outside the view's element.

So if your view's element is table, then the doSomething() function will be called when the keydown event is fired on the table, but it will not be called if the keydown event is fired on another element on the page.

like image 172
Paul Avatar answered Sep 29 '22 22:09

Paul