Data Model of extjs4

Source: Internet
Author: User

Extjs's data model is an important way for the application system to read and store data. extjs4 has greatly improved and added a new Ext. data. model object model class (original 3. X and 2. ext. data. record). You can perform most data operations on the client through the entity model class. It provides data verification at the model level and adds a relational API to associate different models, in addition, the proxy can also directly act on the model class, which means that we can access data without relying on store. The newly added localstorage proxy can use the following statement:CodeData is stored and read on the client. The new reader can even perform nested Data Reading.

In extjs 4, data packets contain a total of more than 40 classes, of which 3 are more important than other classes. They are model (data entity model) and store (Dataset), and proxy (Data proxy)

Ext. data. model data entity model is a reflection of the real world entity objects in the application system. It contains a field set and a function for processing data. Its predecessor is 3. X and ext. data. different from record, the record class greatly enhances the function of the model and has become the core of extjs data packets.

The model data entity model class has four important components:

Fields: Field Definition

Proxy: Data proxy

Associations: Model Association

Validatons: Data Validation

The main configuration items and methods of the model class are as follows:

Table 1-1 main configuration items of Ext. Data. Model

Configuration item

Parameter type

Description

Defaultproxytype String Configure the default proxy type. The default value is 'ajax'
Dirty Boolean Read-Only ID. If the data is modified, the value is true. Otherwise, the value is false.
Editing Boolean Read-Only identifier. If the data is being edited, the value is true. Otherwise, the value is false.
Fields Array Field definition array
Modified Object Key-value pairs of all modified data
Phantom Boolean If the data is not persistent, true is used; otherwise, false is used.
Store Ext. Data. Store Join a dataset through belongs

Table 1-2 Ext. Data. Model

Method Name

Description

Ext. Data. Model (Object Data, Number ID): void Object constructor
Data: contains model fields and associated objects.
ID: Unique ID of the Model
Beginedit: void Start editing. At the beginning of the editing mode, no event is propagated to its dataset store object. When an editing starts, it must be endedit or canceledit.
Canceledit: void Cancels all changes made to the record by the current edit operation.
Commit ([Boolean silent]): void Stores with records are called to submit all changes since the record is created or since the last commit.
Copy ([String id]): Record Copy record
ID: ID of the new record
Destory (Object options): Model Destroy data entities
Options: proxy configuration object
Endedit (Boolean silent): void End editing. If the data is changed, the store with records will be notified.
Silent: if it is true, store data transformation is not notified. The default value is false.
Get (string fieldname): mixed Obtains the field value of the specified name.
Getassociateddata: Object Recursively returning all associated data
Getchanges (): Object Obtains the hash set of fields changed after the self-record is created or the last update is submitted.
GETID: Number Obtain the unique ID assigned to the data model instance.
Getproxy: Ext. Data. Proxy Obtain the proxy object configured on the model object
ID (ext. Data. Model REC): String IDs are generated in sequence. This method is called when a record with no specified ID is created.
REC: Non-Persistent Object
Ismodified (string fieldname): Boolean The value is true if the data of the specified field name has been modified after the self-record is created or the last update is submitted. Otherwise, the value is false.
Isvalid: Boolean Returns true if the data is verified.
Join (store): void Add Model objects to store
Load (Number ID, object config): void Asynchronously clipped data by ID
Config: contains success, failure, and callback functions.
Reject ([Boolean silent]): void Stores with records are called to reject all changes since the record is created or since the last commit. fields are restored to their initial values.
Silent: True. Store Data conversion is not notified.
Save (Object options): Model Save object data through proxy
Set (string | object fieldname, mixed value): void Set the value of a specific field in the Model
Setdirty: void Set record to dirty data
Setid (Number ID): void Set the ID field of the model object
Setproxy (string | object | proxy): void Set the data proxy of the Model
Validate: Ext. Data. Errors Verify the current record value and return the object containing the error message

Table 1-3 main configuration items of Ext. Data. Field

Configuration item

Parameter type

Description

Convert Function A data conversion function used to convert the data read by the data reader. The converted data is stored in the record model object. The following parameter is passed in:
V: Original Value of the mixed field
REC: model object
Dateformat String Date Format String
Defaultvalue Mixed The default value when the field value is null. The default value is ""
Mapping String Path description used by reader to obtain values from data objects. If Ext. data. jsonreader needs to include a JS expression starting from the root in the string. If xmlreader is used, it is an ext that can be referenced to the element in the string. domquery path. if the ing expression mapping is the same as the field name, this attribute can be ignored.
Name String Name of the referenced field in the Model
Persist Boolean Sets whether the field is persistent. If the value is false, the field is excluded from ext. data. model. modified and ext. data. writer. in addition to the writer method, it is useful when the field only saves temporary data from the client. The default value is true.
Sortdir String The initial sorting method, including ascending and descending, ASC or DESC. The default value is ASC.
Sorttype Function Converts a field value to a function that can be sorted. sorttype pre-defines some sort functions.
Type Mixed The Data Types of fields include:
Auto (default value, not converted), String, Int, float, Boolean, date
Usenull Boolean Set when the raw data is converted to the numeric type, if the parsing fails, set usenull to true, the return value is null; otherwise, the return value is 0.

Table 1-4 Ext. Data. validations main Formula

Method Name

Description

Exclusion (Object config, string value): Boolean Exclude verification. If the given value is not in the Set, true is returned.
Config: You need to specify the data set through the list configuration item
Value: The data to be verified.
Format (Object config, string value): Boolean Exclude verification. If the given value is not in the Set, true is returned.
Config: Use the matcher configuration item to specify the regular expression.
Value: The data to be verified.
Sion (Object config, string value): Boolean Contains verification. If the given value is in the Set, true is returned.
Config: You need to specify the data set through the list configuration item
Value: The data to be verified.
Length (Object config, string value): Boolean Returns true if the string length of the given value is within the maximum and minimum values.
Config: You must specify the maximum and minimum values through the max and Min configuration items.
Value: The data to be verified.
Presence (Object config, mixedvalue): Boolean Checks whether the given value is valid. The function returns a value by converting the specified value to a Boolean value.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.