I have a context problem / design problem for my Backbone view.
Goal
The user selects a user from a list / user collection in a separate view.
The mentioned view passes an global event that the
editUserView
receives ("edit-contact"
).The
editUserView
should receive this event and extract the (user)model.id
attribute. By using thismodel.id
I want to update the view with the corresponding object retrieved from the existing view modelTsms.Collection.Users
.
Problem
The context passed to the updateView
function is wrong, and thus I do not have access to the parent views .render()
function. The debugger states "render() is not a function".
Since the context is not that of the parent view I am also unable to set the this.current
variable.
How would I go about solving this problem?
View code
Tsms.Views.editUserView = Backbone.View.extend({
model: Tsms.Collections.Users,
initialize: function(options) {
Tsms.require_template('edituser')
this.template = _.template($('#template_edituser').html());
this.current = -1;
Tsms.vent.on('edit-contact', this.updateView)
},
updateView: function(model) {
this.current = model.id;
this.render();
},
render: function() {
this.$el.html(this.template(this.model.get(this.current).attributes));
return this;
}
});