{{#each category}}
{{#each this}}
<h2>{{this.title}}</h2>
{{#each subcategory}}
{{#each thiss}}
<p>{{thiss.title}}</p>
{{/each}}
{{/each}}
{{/each}}
{{/each}}
我想显示每个类别下的每个子类别。我该怎么办。
这是类别和子类别的控制台输出。类别和子类别是不同的变量。
categoty {
_id: 5 bc380563a8b180c18c63945,
title: 'গৃহস্থালী সামগ্রী',
titleen: 'household',
description: 'Only household Products ',
__v: 0
}, {
_id: 5 bc380ea3a8b180c18c63947,
title: 'ছেলেদের পণ্য',
titleen: 'boysproduct',
description: 'this is only for boys product',
__v: 0
}
subcategoty {
_id: 5 bc3825a3a8b180c18c63948,
title: 'কিচেন এন্ড ডাইনিং',
titleen: 'kitckendinning',
description: 'this subcategoryfor kitchen and dinning section',
category: 'household',
__v: 0
},{
_id: 5 bc384143a8b180c18c6394b,
title: 'কম্পিউটার',
titleen: 'computer',
description: 'computer ',
category: 'electronics item',
__v: 0
}, {
_id: 5 bc384a73a8b180c18c6394c,
title: 'জুতা ও স্যান্ডেল',
titleen: 'Shoes',
description: 'this is boys product section',
category: 'boysproduct',
__v: 0
}, {
_id: 5 bc385033a8b180c18c6394d,
title: 'ঘড়ি',
titleen: 'Watch',
description: 'this is boys product',
category: 'boysproduct',
__v: 0
}
我认为这将帮助您纠正错误。
答案 0 :(得分:0)
我假设category
和subcategory
是列表,如果它们是独立的对象,则可以执行以下操作:
{{#each category}}
<h2>{{this.title}}</h2>
{{#each subcategory}}
<p>{{this.title}}</p>
{{/each}}
{{/each}}
如果subcategory
是category
的属性,则可以执行此操作(使用block parameters可以使代码更具可读性):
{{#each category as |cat|}}
<h2>{{cat.title}}</h2>
{{#each cat.subcategory as |subCat|}}
<p>{{subCat.title}}</p>
{{/each}}
{{/each}}