我尝试使用下划线循环遍历嵌套对象。
我的对象看起来像这样:
var someObject = [{
"name": "Chair",
"title": "Chairs",
"items": [{
"name": "Recliner",
"title": "Recliner Chair",
"type": "Chair",
"quantity": "1"
},
{
"name": "Club/Armchair",
"title": "Club/Armchair",
"type": "Chair",
"quantity": 1
}]
}]
但是当一个返回对象存储在子对象上并进行两次重复
时<%_.each(someObject, function(a){%>
<%_.each(a, function(b){%>
<<%_.each(b.items, function(c){%>
<li><%= c.name + " " + c.title></li>
<%});%>
<%});%>
<%});%>
请帮忙!
答案 0 :(得分:1)
看起来你有一个额外的循环。尝试删除循环
<%_.each(a, function(b){%>
并查看是否修复了它