繁体   English   中英

在快速车把中嵌套{{#each}}吗?

[英]Nested {{#each }} in express-handlebars?

  {{#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
    }

我认为这将帮助您纠正错误。

我假设categorysubcategory是列表,如果它们是独立的对象,则可以执行以下操作:

{{#each category}}
    <h2>{{this.title}}</h2>
    {{#each subcategory}}
        <p>{{this.title}}</p> 
    {{/each}}
{{/each}}

如果subcategory是的属性category可以做到这一点(使用块参数使得代码更易读):

{{#each category as |cat|}}
    <h2>{{cat.title}}</h2>
    {{#each cat.subcategory as |subCat|}}
        <p>{{subCat.title}}</p> 
    {{/each}}
{{/each}}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM