About the deletion of JSON objects

Source: Internet
Author: User

Excerpted from http://www.cnblogs.com/wuyifu/p/3424621.html

A JSON object is generated in the background, but some data may be invalid or illegal, so you need to do some exceptions at the foreground, such as deleting.

There are many ways to delete JSON, directly using the Delete JSON object.

Examples are as follows
JS Code
var columns = [
{Name: "Bigtitle", caption:reportdata.bigtitle,children:[
{Name: "OrgName", Caption: "Organization structure name", Width:100,mode: "String"},
{Name: "Helpinfo", Caption:reportdata.columncaption[0],
Children:[{name: "Workday_month", Caption: "Workdays", Width:80,mode: "Number", Format: "#"},
{Name: "Loggedday_month", caption: "Login Days", Width:80,mode: "Number", Format: "#"}]
},
{Name: "Helpinfo", caption:reportdata.columncaption[1],
Children:[{name: "Workday_week1", Caption: "Workdays", Width:70,mode: "Number", Format: "#"},
{Name: "Loggedday_week1", caption: "Login Days", Width:70,mode: "Number", Format: "#"}]
},
{Name: "Helpinfo", caption:reportdata.columncaption[2],
Children:[{name: "Workday_week2", Caption: "Workdays", Width:70,mode: "Number", Format: "#"},
{Name: "Loggedday_week2", caption: "Login Days", Width:70,mode: "Number", Format: "#"}]
},
{Name: "Helpinfo", Caption:reportdata.columncaption[3],
Children:[{name: "Workday_week3", Caption: "Workdays", Width:70,mode: "Number", Format: "#"},
{Name: "Loggedday_week3", caption: "Login Days", Width:70,mode: "Number", Format: "#"}]
},
{Name: "Helpinfo", Caption:reportdata.columncaption[4],
Children:[{name: "Workday_week4", Caption: "Workdays", Width:70,mode: "Number", Format: "#"},
{Name: "Loggedday_week4", caption: "Login Days", Width:70,mode: "Number", Format: "#"}]
},
{Name: "Helpinfo", Caption:reportdata.columncaption[5],
Children:[{name: "Workday_week5", Caption: "Workdays", Width:70,mode: "Number", Format: "#"},
{Name: "Loggedday_week5", caption: "Login Days", Width:70,mode: "Number", Format: "#"}]
}
]}
];

According to Rtdata.columncaption, if NULL, the node is deleted and is not displayed.

Used Delete columns[0][' children '][6];

Invalid, reported JS error, and then found that the deletion is indeed deleted, but finally left a comma, resulting in IE error, a lot of data found no solution.

Finally, a change of solution.

columns[0][' Children '].pop ();

The pop () method means that the last node is deleted.

The requirements for the work calendar meet that requirement exactly, decreasing from the latter.

Other similar methods are as follows:
var person={name: "Yaoming", Sex: "M", Age: "26"};
JsonObj2.persons.push (person);//array last add a record
JsonObj2.persons.pop ();//Delete last item
JsonObj2.persons.shift ();//Delete first item
JsonObj2.persons.unshift (person);//The array is preceded by a record
As long as the JavaScript-friendly method is available in the array of JSON objects! So there's another way to splice () for CRUD operations!
Delete
JsonObj2.persons.splice (0,1);//start position, delete number
Replace does not delete
var self={name: "Tom", Sex: "M", Age: "24"};
var brother={name: "Mike", Sex: "M", Age: "29"};
JsonObj2.persons.splice (1,0,self,brother);//start position, delete number, insert Object
Replace and delete
var self={name: "Tom", Sex: "M", Age: "24"};
var brother={name: "Mike", Sex: "M", Age: "29"};
JsonObj2.persons.splice (0,1,self,brother);//start position, delete number, insert Object

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.