Introduction to using the global function each in jquery _ jquery-js tutorial

Source: Internet
Author: User
Jquery contains two each values: $ (). the other value of each is $. the difference between each is that the first is the built-in function of the jquery object, and the other is the object's traversal function. jquery contains two each values: $ (). the other value of each is $. the difference between each is that the first is the built-in function of the jquery object, and the other is the object's traversal function. It is generally used to obtain different object data in ajax for traversal. Taking json as an example, jquery's getJSON Shortcut method can be convenient. get the json file in the specified url. jquery will call the js native eval function internally to parse the json text and convert it into a js object. Then, it will traverse it through the each global function to get the Value Syntax each (data, [params], function (current item index, current item), which is also very different from the built-in function each, the index in the built-in function is an identifier used to indicate where the traversal starts. The element specifies the number of elements to be traversed. The each index in the global function refers to the KEY in each KEY-Value Pair in json, that is, the KEY! In the Basic jquery tutorial, the author wrote the corresponding code for example, but could not correctly sample the parameters. The sample code is as follows:

$. Each (data, function (entryIndex, entry) {var html = entry ['condition']}); friends who have read this book may wonder what entryIndex is? In fact, entryIndex is a 'termin', but the author directly fills in the key value from json instead of using the index. After debugging, it is found that the following problems are commonly translated as indexes, in my opinion, the entry should still be called as a key. It is an attribute value that contains a key-value pair. When this attribute is imported using a key as an index, the corresponding value is read through a get accesser similar method, I hope I can answer questions from any of my friends.

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.