Home  >  Article  >  Web Front-end  >  Code based on jquery loop map function_jquery

Code based on jquery loop map function_jquery

WBOY
WBOYOriginal
2016-05-16 18:10:131002browse

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.
Statement:
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