documentcloud/backbone — Issue #956: Render function doesn't extend
Author: jeremyaarts
Created: 2012-02-04 16:08:37+00:00
State: open

When I want to use multiple views for one model, I extend the main view which I first create, as show below.

Somehow, leaving out de 'render' function in de second view stops events in that view from running, so that I have to duplicate the render function in de new view, whereas te only difference is the template. In my app, the render function is a little more complicated than shown below, so it's a bit of a shame to have to duplicate this.

Am I doing something wrong or is this just the way it is?

```javascript
ItemV = Backbone.View.extend({

tagName: "tr",

events: {
"click": "choose"
},

template: _.template($("#item-template").html()),

initialize: function() {
this.model.on('change', this.render, this)
},

render: function() {
this.$el.html(this.template(this.model.toJSON()));
return this
},

choose: function() {
(Lists.get(this.model.get('list'))).set({choice: this.model.id});
}

});

InviteV = ItemV.extend({

template: _.template($("#invite-template").html()),

// this function is exactly the same as in the view it extends
render: function() {
this.$el.html(this.template(this.model.toJSON()));
return this
}

});
```