Chapter 7. Data Models
The model (Ext.data.Model
) is a class that represents some object that your application manages. For example, you might define a model for users, products, cars, or any other real-world object that you want to model in the system.
The Ext.data.Model
is part of the Sencha data package. As described in the preceding chapter, the Sencha architecture uses a pattern similar to MVC, but in the Sencha context the term model includes—besides the model itself (the structure of the data)—the layers record (the specific data) and store (a client-side cache of all records together). In this book, I will use the term model to refer to the Ext.data.Model
.
A model contains fields to structure the data. For example, in the FindACab app, the CabService
has three fields: name
, address
, and total
number of cars. Each record (Ext.data.Record
) is a specific CabService
model object—for example, “Taxi Amsterdam,” which has a total of 14 cars. The Ext.data.Store
is the whole data pool full of records, otherwise known as the client-side cache.
The fields in a model use the Ext.data.Field
class. Every field can be given a data type (see Table 7-1 for an overview of all data types). Data assigned to the field will be autoconverted to the default type. For example, when a field is set to int
and the data 4.8
is passed, then the data will be converted to 5
. When no datatype is specified, the datatype will be set to auto
, which means there is no datatype conversion at all. This might be a ...
Get Hands-On Sencha Touch 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.