I have a backbonejs model called User
. User has properties city, state, and country. I have a function on this model called locationString that outputs a comma separated list based on if properties on the model are presnet or not. i.e. Atlanta, Georgia or Georgia or Atlanta so there are only commas if there need to be.
I am setting the json for my template in the render method of my view by calling var json = model.toJSON()
and then setting location string by doing json.location_string = this.model.locationString();
.
I also am binding the change event of the model to my render method by calling this.model.bind('change', this.render);
in my initialize function on the view.
All other attributes changed on the model update in the view appropriately but the location_string property does not.
Any help will be greatly appreciated
location_string: function() { var loc_str = "";
loc_str += this.city || "";
loc_str += (this.city && this.geo_state) ? ", " : "";
loc_str += this.geo_state || "";
loc_str += (this.geo_state && this.country) ? ", " : "";
loc_str += this.country || "";
return loc_str;
},