Skip to content

ResthubView.render can be called with the wrong context #155

@03xb7

Description

@03xb7

In a ResthubView, one might have the following code:

initialize: function() {
    this.listenTo(this.collection,'change', _.bind(this.render,this));
}

This allows the view to be re-rendered when a model attribute changes. As designed by Backbone, the render method will be called with the modified model as parameter.

The problem is that ResthubView.render assume that first param is the context object. In the above situation, it should be a Collection but render is called with a Model instance due to Backbone design. It results in strange behavior when context is JSONified.

A quick workaround is to explicitly call renderwith no argument:

initialize: function() {
        this.listenTo(this.collection,'change', _.bind(function(){
            this.render();
        },this));
    },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions