Backbone Jsonify alters and provides a extended configuration to the "toJSON" method for models and collections. In general terms, the library enhances it by the following features:
The new configuration options accepted by "toJSON" function are described below:
model String, String[], Boolean, or Function. Returns the object which represents the model but only picks the provided attribute/s.
The function looks through each attribute in the model, and picks all the attributes that pass a truth test defined by the function, which is invoked with up to three arguments; (value [, index|key, object]).
String, String[], Boolean or Function. Returns the object which represents the model but omits the provided attribute/s.
The function looks through each attribute in the model, and omits all the attributes that pass a truth test defined by the function, which is invoked with up to three arguments; (value [, index|key, object]).
Boolean. Whether or not to copy deeply model's attributes which are array or objects.
var artist = firstName: "Wassily" lastName: "Kandinsky"; artist; // Outputs {firstName: "Wassily"} artist; // Outputs {lastName: "Kandinsky"} artist; artist; // Outputs {firstName: "Wassily", age: 26} artist; // Outputs {lastName: "Kandinsky"} Supermodel is a Backbone plugin for model tracking and relationships between models. Backbone.Jsonify has been adapted to work along such library and it provides more options to address the jsonify process of the relationships.
For using it, it is needed to include the Supermodel library just before supermodel.jsonify.js or the minimized version of the plugin.
Serialices the model associations by a configuration.
Object representing:
'*': defaultConfiguration // Takes a default configuration for all associations (optional) associationName : configuration // [...] more association configs The Configuration may accept a boolean or an object.
or a Function invoked with the following interface:
and tests which associations it must include.
A Function that tests which attributes for each association must be included.
A Function that tests which attributes for each association must be excluded.
Boolean. Performs a deep serialization of the model and the relationships.
First install locally all the required development dependencies.
npm installgruntgrunt basegrunt supermodelgrunt testIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.
Read the CHANGELOG.md file distributed with the project.
Read the LICENSE-MIT file distributed with the project.