All posts tagged model

Backbone View-Model Binding

This article briefly discusses how the Backbone.View class is normally used and then introduces a new class that helps makes it easy to synchronize your models and views.

The Backbone.View class helps you do a couple of important things that I’ll discuss in very brief detail:  (I assume that you are already familiar with Backbone.Views)

  • Create browser DOM elements
  • Listen to DOM element events
  • Listen to model events

Create browser DOM elements:

Backbone.View objects have a… Read the rest

There is no magic behind backbone.js model.isNew()

model.isNew() can be quite useful, this method can be interesting when handling and changing forms behaviors from adding new items, to updating and deleting them. At first I did not quite understand how isNew() was working internally and, one day it just stopped working and that was frustrating!

It’s all about the id

One thing I like to do is prepopulate my fields with defaults values. Backbone has a great feature for that, when instantiating a model you can pass… Read the rest

Working with api responses in backbone.js using parse

One backbone.js behavior that was kind of upsetting me recently is the fact that it re-syncs your model after you save it on the server.

You know, you just set a model you changed, save it on the server in the background and continue your day in your application. Backbone however awaits patiently the response from the server api, and if the response does not correspond with your current model state, it sets the response attributes back to your… Read the rest