I canβt understand what happened. When I click on the model name, it selects all the models in the collection at once, and does not select one model. If I translate this event from logView to logsView, it works correctly, but does not have access to the model, I can find this model using an index or ant with a different model identifier, but I do not think this is a good way.
var Log = Backbone.Model.extend({}); window.LogsList = Backbone.Collection.extend({ model:Log, url:function (tag) { this.url = '/logs/' + tag; return this; } }); window.colList = new LogsList(); window.logView = Backbone.View.extend({ el:$('.accordion'), template:_.template($('#log').html()), initialize:function () { this.model.bind('add', this.render, this); }, events:{ "click .accordion-toggle" :"getLogBody" }, render:function () { return this.template(this.model.toJSON()); }, getLogBody:function () { this.model.fetch(); } }); window.LogsView = Backbone.View.extend({ el:$("#content"), initialize:function (options) { colList.bind('reset', this.addAll, this); colList.url(options.data).fetch(); }, addOne:function (model) { var view = new logView({model:model}); $("#accordion").append(view.render()); }, addAll:function () { colList.each(this.addOne); } }); window.listView = new LogsView({data:"Visa_Cl"});
nateless
source share