【问题标题】:How can I show object inside array in JSON in handlebars with NodeJs Express如何使用 NodeJs Express 在车把中以 JSON 格式显示数组内的对象
【发布时间】:2018-03-04 08:24:52
【问题描述】:

这是 JSON:

{ 
"_id" : ObjectId("59c3edd10e2a6f083e858036"), 
"email" : "aa@aa.com", 
"username" : "aa", 
"password" : "$2a$10$WcUgbqFjsx.0BwkdEyDNP.R84vz1d7faaL8K0ORcIoBOXOAHxCS3.", 
"words" : [
    {
        "Name" : "xyz"
    }
], 
"title" : [

], 
"__v" : NumberInt(0), 
"name" : "obbk"
}

这是我在words中显示数据的代码

{{#users}}
    {{#words}}
        <h3>{{this.Name}}</h3>
    {{/words}}
{{/users}}

但它不起作用。

所以我想知道如何解决这个问题,如何在words 中显示Name,在nodejs 中使用把手作为模板从MongoDB 数据库中JSON 的数组中获取数据。

【问题讨论】:

    标签: javascript json node.js express handlebars.js


    【解决方案1】:

    用途:

    {{#users}}
        {{#words}}
            <h3>{{Name}}</h3>
        {{/words}}
    {{/users}}
    

    请注意,在外循环(通过users)中,您已经在不使用this 关键字的情况下访问了words 属性,因此请保持内循环内的逻辑(通过words)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 2018-03-30
      • 2023-03-25
      • 2021-03-01
      • 1970-01-01
      相关资源
      最近更新 更多