Ehsan Ghanbari

Experience, DotNet, Solutions

Model classes in BackboneJS

backbonJS is based on MV* patterns and designed for developing single page applications. It provides some basic and essential functionalities like attributes, events, and validations for models. A model of backboneJS encapsulates model data that is further available for an application to interact with the user interface.

"Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface. With Backbone, you represent your data as Models, which can be created, validated, destroyed, and saved to the server."

As I'm only talking about backbonJS model classes in this blog post, so take a look at a model class as an example:

var Info= Backbone.Model.extend({

   defaults: {

        'name': 'Ehsan',

        'address': {

            'street': '14st Street'

            'city': 'Tehran',

            'Phone': +9809193782914

        }

   }

});

The most important part of the above object is Backbone.Model.extend which is a backboneJS Operand. you can also create an object from the above Model:

var infoObj= new Info({

    'name': 'Ben',

    'phone' '+79***********'

});

by creating an object, you will get a reference to that object, and any manipulation to the object will directly manipulate the actual object in the model. For example, you can manipulate the above model  like this:

Info.set('name', 'Jim.', { validate: true });

 

About Me

Ehsan Ghanbari

Hi! my name is Ehsan. I'm a developer, passionate technologist, and fan of clean code. I'm interested in enterprise and large-scale applications architecture and design patterns. I spend a lot of time on software architecture. Since 2008, I've been as a developer for different companies and organizations and I've been focusing on Microsoft ecosystem all the time. During the past years, Read More

Post Tags
Pending Blog Posts
using Elmah in asp.net MVC4
Using FluentSecurity in MVC
Strategic design
Factory Pattern
time out pattern in ajax
Redis as a cache server
How to use PagedList In asp.net MVC
Multiple submit buttons in asp.net MVC
Domain driven design VS model driven architecture
What's the DDD-lite?
comments powered by Disqus