好吧,我難住這個。 我需要通過這些迭代,所以我可以按類別的列表所以像如何通過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 –