好吧,我难住这个。 我需要通过这些迭代,所以我可以按类别的列表所以像如何通过JS中的嵌套对象进行迭代
商业书籍
书1
书2
书3
烹饪图书
等。
但无法弄清楚如何遍历嵌套的对象。 带或不带jQuery是罚款
window.books = {
"Business Books": [
{
Title: "Finance 101",
Description: "Info for Finance 101 book goes here."
},
{
Title: "Economics 123",
Description: "Info for Economics 123 book goes here."
},
{
Title: "Statistics for Beginners",
Description: "Learn about Statistics."
}
],
"Cooking Books": [
{
Title: "Lowfat Treats",
Description: "Eat a lowfat Diet"
},
{
Title: "Chocolate Lovers",
Description: "Eat a lot of chocolate"
},
{
Title: "Book of Brownies",
Description: "Stuff about Brownies"
}
],
"IT Books": [
{
Title: "Windows XP",
Description: "Please go away"
},
{
Title: "Linux",
Description: "A how to guide."
},
{
Title: "Unix",
Description: "All about Unix."
},
{
Title: "Mac",
Description: "Costs too much."
}
],
};
遍历对象的属性。每个对象都有一组值。遍历数组。这需要一个嵌套for循环。看看https://developer.mozilla.org/en/JavaScript/Guide/Statements#Loop_Statements –