我有一个要循环的对象。在我循环对象之前,我决定将值存储在单独的变量中,为此我使用对象表示法来获取值..我对“选项”和“行”变得未定义 - 这两者都有什么问题使用权?
或任何人建议我访问这些节点的正确方法。
这是我的对象:
var ob = {
"DashBoard":[
{"title":"DashBoard"},
{"widget":[{"slide":"To do"},{"slide":"Teamspace"},{"slide":"Recent Activity"}]},
{"activity":[
{"option":[{"show":"Volvo"},{"show":"Benz"},{"show":"Honda"}]},
{"rows":[
{"title":"Advert1", "text":"sample text1", "date":"22-06-2013"},
{"title":"Advert2", "text":"sample text2", "date":"22-06-2014"},
{"title":"Advert3", "text":"sample text3", "date":"22-06-2015"},
{"title":"Advert4", "text":"sample text4", "date":"22-06-2016"},
{"title":"Advert5", "text":"sample text5", "date":"22-06-2017"}
]}
]}
]
}
var title = ob.DashBoard[0], widget= ob.DashBoard[1], option = ob.DashBoard[2]["option"], rows = ob.DashBoard[2]["rows"];
console.log(option); //undefined
console.log(rows); //undefined
我在这两种情况下都得到未定义的结果......