Search code examples
marionette

Pass a property of the model to the template in ItemView


I want to pass a property of my model to the template, so I presume I need a serializeData function, I tried this

serializeData:function(){
    return this.model.toJSON().extend({_schema:this.model.schema});
}

but it complained about not being able to extend the output of toJSON. This must be a standard trick, stick some value from the prototype into the serialised form so the template can get it's hands on it.


Solution

  • Use templateHelpers for this use case – serializeData works better for replacing the model attributes entirely, or scoping them down.

    templateHelpers: function()
    {
        return { _schema: this.model.schema };
    }