Ext. Data. Store example (4)

Source: Internet
Author: User
4. Update store data

You can use add (ext. Data. Record [] records) to add one or more records to the end of the store. The parameters used can be a record instance, as shown below:Code.

Store. Add (New personrecord ({

Name: 'other ',

Sex: 0

}));

Add () can also add a record array, as shown in the following code:

Store. Add ([New personrecord ({

Name: 'other1 ',

Sex: 0

}), New personrecord ({

Name: 'other2 ',

Sex: 0

})]);

The add () function adds new data to the end of the store every time, which may damage the original ordering method of the store. You can use the addsorted () function to insert new data to the corresponding location based on the original store sorting method. It sorts the store immediately after adding new data. This ensures that the data in the store is displayed in an orderly manner, as shown in the following code.

Store. addsorted (New personrecord ({

Name: 'lili ',

Sex: 1

}));

Store searches for the index location that the record should be inserted based on the sorting information, and then inserts data according to the obtained index location to sort the whole. This function requires local sorting for the store in advance, otherwise it will not work.

If you want to specify the index location for data insertion, you can use the insert () function. Its first parameter indicates the index location of the inserted data. You can use the record instance or the array of the record instance as the parameter. After the insertion, the subsequent data is automatically moved back, as shown in the following code.

Store. insert (3, new personrecord ({

Name: 'other ',

Sex: 0

}));

Store. insert (3, [New personrecord ({

Name: 'other1 ',

Sex: 0

}), New personrecord ({

Name: 'other2 ',

Sex: 0

})]);

You can use the remove () and removeall () functions to delete the specified record and clear the data in the entire store, as shown in the following code.

Store. Remove (store. getat (0 ));

Store. removeall ();

The store does not provide a specific operation to modify a row of records. We need to first obtain a record from the store. The changes to the internal data of this record are directly reflected on the store, as shown in the following code.

Store. getat (0). Set ('name', 'xxxx ');

After modifying the internal data of a record, you have two options: Execute rejectchanges () to undo all the modifications, restore the modified record to the original state, and execute commitchanges () to submit data modifications. Before you perform the Undo and commit operations, you can use getmodifiedrecords () to obtain the record array modified in the store.

the parameter related to data modification is prunemodifiedrecords. If this parameter is set to true, each time a delete or reload operation is executed, all modifications are cleared. In this way, after each deletion or reload operation, getmodifiedrecords () returns an empty array, otherwise it will still get the last modified record records.

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.