How data is cloned in Ext. Data. Store

Source: Internet
Author: User

When developing the front-end time, you need. data. store the data in the store to a variable first, then the data in the store will be cleared, and finally the data in the variable will be loaded into the store.

The Code is as follows:

var tempData = this.store.data.clone();/* Something else */this.store.loadData([]);/* Something else */this.store.loadData(tempData);

At this time, you will find that when the last row is executed, the size of tempdata is already 0. Why?

The answer is that the clone of data (ext. util. mixedcollection) is a light copy.

Clone (): Ext. util. mixedcollection

Creates a shallow copy of this collection

Available since:4.0.0

Returns
  • Ext. util. mixedcollection

To meet our needs, we must implement a deepcopy operation by ourselves:

var tempData = this.store.data;var r = new Ext.util.MixedCollection();var keys = tempData.keys;var items = tempData.items;for(var i = 0, len = items.length; i < len; i++){    r.add(keys[i], items[i].copy());}this.store.loadData([]);for (var i = 0, len = r.items.length; i < len; i++) {    this.store.loadData([r.items[i].data], true);}

  

 

How data is cloned in Ext. Data. Store

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.