Bidirectional conversion between forms and Business Objects Using JSON

Source: Internet
Author: User

If you can automate the two-way conversion of objects (that is, you can convert objects into forms and directly convert forms into objects ). Objects in JavaScript are tough.
(Flexibility), with the code can modify the object members at any time. You can easily bind fields on the client using Js. The client can use the same javascrui.
Processing. For example:
VaR person = {
Name: 'lisq ',
Birthday: '20140901'
}
<Form ID = "formperson">
<Input name = "name"/>
<Input name = "Birthplace"/>
</Form>
<SCRIPT>
For (var p in person ){
$ (P). value = person [p];
}
</SCRIPT>
The submission form is also changed from the traditional form. Submit () to, convert the form to the JSON format first, and then submit the form. The Code is as follows:
<SCRIPT>
VaR P = formperson. serialize (true)
VaR paras = 'o = '+ P. tojsonstring ()
Request (URL, paras, function (){
Alert ('saved successfully! ')
})
</SCRIPT>
Server
The Field Obtained by the server is only O, not the previous name, birthplace. O is the converted string {Name:
'Lisq', birthday: '000000'}. The server performs a JSON-to-C # object conversion. Person P =
JSON. serialize (request ["O"], typeof (person), if the data access layer has a good implementation, then add a line of code to achieve p. save () (see nhib.pdf ).

Related Article

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.