вместо того, чтобы перехватывать событие rowClick в главном представлении, я предлагаю вам перехватить его в представлении строк и пропустить через систему событий магистрали ...
Ваше родительское представление может привязываться к его строкам, чтобы поймать клик.
есть два способа сделать это,
запускает пользовательское событие в модели вашей строки и позволяет родителю связываться с каждой моделью в коллекции, хотя это выглядит как взлом и снижение производительности.
Я предлагаю сделать это с помощью агрегатора событий:
var App = {
events: _.extend({}, Backbone.Events);
};
var myGeneralView = Backbone.Views.extend({
initialize: function() {
_.bindAll(this, "catchMyCustomEvent";
/*
and here you bind to that event on the event aggregator and
tell it to execute your custom made function when it is triggered.
You can name it any way you want, you can namespace
custom events with a prefix and a ':'.
*/
App.events.bind('rowView:rowClicked');
},
catchMyCustomEvent: function (model, e) {
alert("this is the model that was clicked: " + model.get("myproperty"));
}
// other methods you will probably have here...
});
var myRowView = Backbone.Views.extend({
tagName: "li",
className: "document-row",
events: {
"click" : "myRowClicked"
},
initialize: function() {
_.bindAll(this, "myRowClicked");
},
myRowClicked: function (e) {
/*
You pass your model and your event to the event aggregator
*/
App.events.trigger('rowView:rowClicked', this.model, e);
}
});