Ext. Data. Record example

Source: Internet
Author: User

Ext. Data. Record is an object that sets the internal data type. It is the most basic component of Ext. Data. Store. If you think of Ext. Data. Store as a two-dimensional table, each row of it corresponds to an Ext. Data. Record instance.

The main function of Ext. Data. Record is to save data and record the modification status when internal data changes. It can also retain the original value before modification.

We usually start with the CREATE () function when using Ext. Data. Record. First, we use the CREATE () function to create a custom record type, as shown in the following figure.Code.

 

VaR personrecord = ext. Data. Record. Create ([

{Name: 'name', type: 'string '},

{Name: 'sex', type: 'int '}

]);

 

Personrecord is the new type defined by us. It includes two attributes: name of the string type and sex of the integer type. Then, we use the new keyword to create an instance of personrecord, as shown in the following code.

 

VaR boy = new personrecord ({

Name: 'boys ',

Sex: 0

});

 

When creating an object, you can directly assign an initial value to the object through the constructor, assign 'boys' to name, and assign 0 to sex.

Now we get the personrecord instance boy. How can we get its attributes? You can obtain the name attribute data in boy in the following three methods.

 

Alert (boy. Data. Name );

Alert (boy. Data ['name']);

Alert (boy. Get ('name '));

 

This involves the data attribute of Ext. Data. record. This is a public attribute defined in Ext. Data. Record to save all data of the current record object. It is a JSON object that can obtain the required data directly from it. You can use the get () function of Ext. Data. Record to conveniently obtain the specified attribute value from the data attribute.

If you need to modify the data in boy, do not directly operate data using the following methods, as shown in the following code.

 

Boy. Data. Name = 'Boy name ';

Boy. Data ['name'] = 'Boy name ';

Instead, use the Set () function, as shown in the following code.

 

Boy. Set ('name', 'body name ');

 

The Set () function determines whether the property value has changed. If it changes, you need to set the dirty attribute of the current object to true and put the original modified value into the modified object, for other functions. If you operate values in data directly, record cannot record the modification of attribute data.

After the attribute data of a record is modified, we can perform the following operations.

Q commit () (submit): This function sets dirty to false and deletes the original data saved in modified.

Q reject () (UNDO): This function restores the modified attribute values in data to the original data saved in modified, and sets dirty to false, delete the modified object that saves the original data.

Q getchanges (): This function places the modified attributes and data in a JSON object and returns the modified data. In the preceding example, getchanges () returns {Name: 'body name '}.

Q we can also call ismodified () to determine whether the data in the current record has been modified.

Ext. Data. Record also provides the copy () function for copying record instances ().

 

VaR copyboy = boy. Copy ();

 

In this way, we get a copy of boy, which contains the data of boy, but the copy () function does not copy additional attribute values such as dirty and modified.

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.