我正在构建一个带有主干js的小应用程序,其网格应该可以使用键盘导航。我无法获得视图中的按键或键盘事件。
以下是代码:
// 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 包含一个或多个 App.Views.Detail 。它应该能够使用箭头键导航每个视图,但 App.Views.Details 中没有看到任何事件。
也许这不是正确的方法,但我是骨干的新手,我可以提出建议。 提前谢谢你:)