0

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.

Mark Lester
  • 363
  • 4
  • 13

2 Answers2

1

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 };
}
Hein Haraldson Berg
  • 1,108
  • 11
  • 24
0

Harladson's answers is the best, but in case someone else comes looking different approach you can do this:

serializeData:function(){
    var data = this.model.toJSON();
    data._schema = this.model.schema;
    return data;
}
Belac
  • 953
  • 1
  • 6
  • 10
  • I guess what I want is to be able to go {{#each %schema}} , which would be nice but hard. Template helper is the way to keep me going – Mark Lester Dec 03 '15 at 14:29