Home > Web Front-end > JS Tutorial > body text

Code based on jquery loop map function_jquery

WBOY
Release: 2016-05-16 18:10:13
Original
1001 people have browsed it

Without further ado, look at the code

Copy the code The code is as follows:

var map = {
Place names: ["Beijing", "Tianjin", "Shanghai"],
Ethnicity: ["Han", "Tibetan", "Uyghur"]
};

$.each (map,function(key,values){
console.log(key);
$(values).each(function(){
console.log("t" this);
});
});

If firebug is installed, the console will output the following tree structure:

Place name
Beijing
Tianjin
Shanghai
Ethnicity
Han Chinese
Tibetan
Uyghur

Note: The difference between $().each and $.each in jquery is that the former can only traverse arrays, while the latter can traverse Arrays and objects

Note: The place name ontology in the sinobook project is classified by type. The background package is a map (key is a relationship type, and the value is a list). The frontend can output it in the above way.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!