Book Image

Learning Ext JS_Fourth Edition

Book Image

Learning Ext JS_Fourth Edition

Overview of this book

Table of Contents (22 chapters)
Learning Ext JS Fourth Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Models


Models represent objects or entities inside our application, for example, Clients, Users, Invoices, and so on. Those models will be used by the data stores. We can define as many models as we need inside our application.

A model may contain fields, validations, and relationships between other models. We can also set a proxy to persist and pull our data.

Note

As of version 5.x, field definitions can be optional unless you need conversion, validations, or set an implicit data type. For more information, take a look at http://docs.sencha.com/extjs/5.1/whats_new/5.0/whats_new.html#Models.

To create a model, let's write the following code:

Ext.define('Myapp.model.Client',{
extend:'Ext.data.Model',  // step 1
idProperty:'clientId ', // step 2
fields:[// step 3
  {name: 'clientId', type: 'int'},
  {name: 'name'    , type: 'string'},
  {name: 'phone'   , type: 'string'},
  {name: 'website' , type: 'string'},
  {name: 'status'  , type: 'string'},
  {name: 'clientSince', type: 'date', dateFormat...