簡體   English   中英

如何使用NodeJs Express在車把的JSON中顯示數組中的對象

[英]How can I show object inside array in JSON in handlebars with NodeJs Express

這是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內的數組獲取數據。

采用:

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

請注意,在外環(通過users )你已經訪問words性能,而無需使用this關鍵字,因此跟上這種邏輯內環(通過內部words )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM