Backbone Tutorials

Models and Views

The one most vital factor that Backbone can assist you with is holding your small business logic separate out of your consumer interface. When the 2 are entangled, change is difficult; when logic does not rely on UI, your interface turns into simpler to work with.

Model

Orchestrates information and enterprise logic.
Masses and saves information from the server.
Emits events when information modifications.

View

Listens for modifications and renders UI.
Handles consumer enter and interactivity.
Sends captured enter to the model.

A Model manages an inner desk of information attributes, and triggers “change” events when any of its information is modified. Models deal with syncing information with a persistence layer — often a REST API with a backing database. Design your models because the atomic reusable objects containing all the helpful features for manipulating their particular bit of information. Models ought to have the ability to be handed round all through your app, and used anyplace that bit of information is required.

A View is an atomic chunk of consumer interface. It usually renders the information from a selected model, or variety of models — however views may also be data-less chunks of UI that stand alone. Models needs to be typically unaware of views. As an alternative, views take heed to the model “change” events, and react or re-render themselves appropriately.