Your definition of FullName makes no sense, so I'm going to suggest that you really meant it:
Person = Backbone.Model.extend({ FullName: function() { return this.get("firstName") + " " + this.get("lastName"); } });
Usually you call toJSON your models to serialize them for use by the template:
var html = template({ person: person.toJSON() })
default toJSON simply returns a (shallow) copy of the modelβs internal attributes. Presumably, attributes have the properties firstName and lastName , but FullName is a function on the model, so it will not be in the attributes.
You can provide your own toJSON :
toJSON: function() { var j = _(this.attributes).clone(); j.FullName = this.FullName(); return j; }
and then you will have FullName in your template. However, toJSON also used to serialize the model to send data to the server; your server will see FullName , and this may be frustrating about this. You can add another serializer specifically for templates:
// `serialize` is another common name for this for_template: function() { var j = this.toJSON(); j.FullName = this.FullName(); return j; }
and then use this function to provide data for your templates:
var html = template({ person: person.for_template() });
mu is too short
source share