I'm building a small application with backbone js, with a grid that should be navigable using the keyboard. I can't get anything on keypress or keyup events in the views.
Here is the code:
// ALL DETAILS VIEW [wrapper]
App.Views.Details = Backbone.View.extend({
tagName: 'div',
initialize: function() {
this.collection.on( 'add', this.addOne, this );
},
events: {
'keypress': 'keyAction',
},
render: function() {
this.collection.each( this.addOne, this );
return this;
},
addOne: function(detail) {
var detailView = new App.Views.Detail({ model: detail, collection: this.collection });
this.$el.append(detailView.render().el);
},
keyAction: function(e) {
console.log('here');
}
});
// SINGLE DETAIL VIEW
App.Views.Detail = Backbone.View.extend({
tagName: 'div',
template: template('detailView'),
initialize: function() {
this.model.on( 'change', this.render, this );
},
edit: function(e) {
var field = $(e.target).closest('.editable');
field.addClass('editing');
field.find('input').focus().select();
},
render: function() {
this.$el.html( this.template( this.model.toJSON() ) );
return this;
}
});
App.Views.Details contains one or many App.Views.Detail. It should be able to navigate each view using the arrow keys, but no events are seen in App.Views.Details.
Maybe this isn't the right way to do this, but I'm new at backbone and I'm open for suggestions. Thank you in advance :)