| 1. |
What Are The Tips/tricks/practice, With Respect To Model, You Follow? |
|
Answer» Below are some practices you should follow while working with Backbone models: Get all the Current ATTRIBUTES obj.attributes gives a direct reference to the attributes and you should be careful when playing with it. Best practice would SUGGEST that you use .set() to edit attributes of a model to take advantage of backbone listeners. var person = new Person({ NAME: "Thomas", age: 67}); var attributes = person.toJSON(); // { name: "Thomas", age: 67} /* This simply returns a copy of the current attributes. */ var attributes = person.attributes; Validate Data Before You Set or Save It Always implement validate() method so that Backbone validates the input before setting any attribute value. It ensures that invalid data is not stored on your server. Person = Backbone.Model.extend({ Below are some practices you should follow while working with Backbone models: Get all the Current Attributes obj.attributes gives a direct reference to the attributes and you should be careful when playing with it. Best practice would suggest that you use .set() to edit attributes of a model to take advantage of backbone listeners. var person = new Person({ name: "Thomas", age: 67}); var attributes = person.toJSON(); // { name: "Thomas", age: 67} /* This simply returns a copy of the current attributes. */ var attributes = person.attributes; Validate Data Before You Set or Save It Always implement validate() method so that Backbone validates the input before setting any attribute value. It ensures that invalid data is not stored on your server. Person = Backbone.Model.extend({ |
|