Ember.js 无法访问模板中模型对象的嵌套节点的数据
我已经发布了我的代码。 这里我得到了Ember.js 无法访问模板中模型对象的嵌套节点的数据,ember.js,handlebars.js,Ember.js,Handlebars.js,我已经发布了我的代码。 这里我得到了home\u产品的第一个节点的数据 "contents": [ { "id": "1", "product_name": "abc11" }, { "id": "2", "product_name": "abc12" } ] 无法获取第二个节点的数据,即 "contents":
home\u产品的第一个节点的数据
"contents": [
{
"id": "1",
"product_name": "abc11"
},
{
"id": "2",
"product_name": "abc12"
}
]
无法获取第二个节点的数据,即
"contents": [
{
"id": "1",
"product_name": "abc21"
},
{
"id": "2",
"product_name": "abc22"
}
]
每次我得到相同的数据,即第一个节点的数据
有谁能帮我解决这个问题吗?您的
装置嵌套错误,您应该只有一个内容
数组,从而导致:
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"
}
]
}
]
}
];
希望能有帮助
更新
每个home\u产品
中嵌套的内容
数组需要不同的id
,尽管它们位于独立的数组中,否则会被视为一个数组并被覆盖:
更新的固定装置
自定义索引模板
{{{#模型中的每个应用程序}
{{application.name}
{{#应用程序中的每个homeproduct.home#U products}
- {{homeproduct.name}
{{{#homeproduct.contents中的每个项目}
- {{item.product_name}
{{/每个}}
{{/每个}}
{{/每个}}
您的装置嵌套错误,您应该只有一个内容
数组,从而导致:
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"
}
]
}
]
}
];
希望能有帮助
更新
每个home\u产品
中嵌套的内容
数组需要不同的id
,尽管它们位于独立的数组中,否则会被视为一个数组并被覆盖:
更新的固定装置
自定义索引模板
{{{#模型中的每个应用程序}
{{application.name}
{{#应用程序中的每个homeproduct.home#U products}
- {{homeproduct.name}
{{{#homeproduct.contents中的每个项目}
- {{item.product_name}
{{/每个}}
{{/每个}}
{{/每个}}
否,“home_products”(在上述夹具中)的每个节点都包含数组。如何处理这种情况?@user2625690,啊,好吧,让我做一个不同的版本,然后我会更新我的答案……谢谢,我在等待你的答复。@user2625690,你有了,享受:)不,“home_products”(在上述装置中)的每个节点都包含数组。如何处理这种情况?@user2625690,啊,好吧,让我做一个不同的版本,然后我会更新我的答案……谢谢,我在等待你的答复。@user2625690,你有了,享受:)
<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>