你FIXTURES
的嵌套错误,你应该只有一个contents
数组,导致:
Astcart.Application.FIXTURES=[
{
"home_products": [
{
"id": "1",
"name": "Mobiles & Accessories",
"contents": [
{
"id": "1",
"product_name": "abc11"
},
{
"id": "2",
"product_name": "abc12"
},
{
"id": "3",
"product_name": "abc21"
},
{
"id": "4",
"product_name": "abc22"
},
{
"id": "5",
"product_name": "abc31"
},
{
"id": "6",
"product_name": "abc32"
}
]
}
]
}
];
工作示例。
希望能帮助到你。
更新
它缝合contents
每个内部的嵌套数组home_product
需要不同id
的 's,尽管它们位于独立的数组中,否则它们会被视为一个并被覆盖:
更新的夹具
Astcart.Application.FIXTURES = [
{
"id": "1",
"name": "Application 1",
"home_products": [
{
"id": "1",
"name": "Mobiles & Accessories",
"contents": [
{
"id": "1",
"product_name": "abc11"
},
{
"id": "2",
"product_name": "abc12"
},
{
"id": "3",
"product_name": "abc21"
},
{
"id": "4",
"product_name": "abc22"
},
{
"id": "5",
"product_name": "abc31"
},
{
"id": "6",
"product_name": "abc32"
}
]
},
{
"id": "2",
"name": "Bags & Cases",
"contents": [
{
"id": "7",
"product_name": "def11"
},
{
"id": "8",
"product_name": "def12"
},
{
"id": "9",
"product_name": "def21"
},
{
"id": "10",
"product_name": "def22"
},
{
"id": "11",
"product_name": "def31"
},
{
"id": "12",
"product_name": "def32"
}
]
}
]
}
];
更新的索引模板
<script type="text/x-handlebars" data-template-name="index">
<ol>
{{#each application in model}}
<li>{{application.name}}</li>
<ul>
{{#each homeproduct in application.home_products}}
<li>{{homeproduct.name}}</li>
<ul>
{{#each item in homeproduct.contents}}
<li>{{item.product_name}}</li>
{{/each}}
</ul>
{{/each}}
</ul>
{{/each}}
</ol>
</script>
更新了 jsfiddle。