2015-08-04 Personal Customization (cyclic traps in Nodejs)

Source: Internet
Author: User
When doing user customization, that is, for each user just show him to participate in the type of insurance (sistype), encountered Nodejs asynchronous programming problem, because in the background Contrller Getsistyoe, I need to first of the Payment History table user Check, If the usename in the Payhist table, then the type of its participation in a corresponding setting, for example, in the pension table after the existence of the user username, then the corresponding Sistype table sign should be sign=1,kind= old age, These two attributes are taken out of the screen after the user logs in.

Because the operation of the five tables is exactly the same, avoid code duplication ....

However, the problem encountered:

Initially, you only need to payhist the table name and sign property values. Consider using a loop array to place the range of values it needs to change into an array. Through the I variable control implementation, but because the Nodejs itself asynchronous, so can not be implemented, the data is taken out all first, and then proceed to the next sign value of the loop, resulting in the last sign of the property value.

Second, consider avoiding the loop, using the function to implement, but this will still be affected by the asynchronous programming, because when the results are still all completed two functions to determine whether username exist, from the Payhist1payhist2 table after the data is taken out, Then the second Getsistype function, and this is the last Payhist table, the judgment of sign is only the last table corresponding, so also can not be implemented.

Finally, the practice of repeating code is used ... : Payhist1 payhist2 Payhist3

2015-08-04 Personal Customization (cyclic traps in Nodejs)

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.