使用Pug访问嵌套数组

时间:2017-08-02 09:28:44

标签: express nested pug

我有以下内容正在被MongoDB拉出来,我正试图在pug中显示“url”和“applications”,来自url的数据显示正确,但是我无法从“应用程序”访问数据

{
        "_id" : ObjectId("5975cdfeb39f71f2fcc2a09d"),
        "url" : "http://www.opencolleges.edu.au",
        "applications" : [
                {
                        "name" : "AppNexus",
                        "confidence" : "100",
                        "version" : "",
                        "icon" : "AppNexus.svg",
                        "website" : "http://appnexus.com",
                        "categories" : [
                                "Advertising Networks"
                        ]
                },
                {
                        "name" : "CloudFlare",
                        "confidence" : "100",
                        "version" : "",
                        "icon" : "CloudFlare.svg",
                        "website" : "http://www.cloudflare.com",
                        "categories" : [
                                "CDN"
                        ]
                },
                {
                        "name" : "Crazy Egg",
                        "confidence" : "100",
                        "version" : "",
                        "icon" : "Crazy Egg.png",
                        "website" : "http://crazyegg.com",
                        "categories" : [
                                "Analytics"
                        ]
                },
                {
                        "name" : "Google AdSense",
                        "confidence" : "100",
                        "version" : "",
                        "icon" : "Google AdSense.svg",
                        "website" : "http://google.com/adsense",
                        "categories" : [
                                "Advertising Networks"
                        ]
                },
                {
                        "name" : "Google Analytics",
                        "confidence" : "100",
                        "version" : "UA",
                        "icon" : "Google Analytics.svg",
                        "website" : "http://google.com/analytics",
                        "categories" : [
                                "Analytics"
                        ]
                },
                {
                        "name" : "Google Font API",
                        "confidence" : "100",
                        "version" : "",
                        "icon" : "Google Font API.png",
                        "website" : "http://google.com/fonts",
                        "categories" : [
                                "Font Scripts"
                        ]
                },
                {
                        "name" : "Google Tag Manager",
                        "confidence" : "100",
                        "version" : "",
                        "icon" : "Google Tag Manager.png",
                        "website" : "http://www.google.com/tagmanager",
                        "categories" : [
                                "Tag Managers"
                        ]
                },
                {
                        "name" : "New Relic",
                        "confidence" : "100",
                        "version" : "",
                        "icon" : "New Relic.png",
                        "website" : "http://newrelic.com",
                        "categories" : [
                                "Analytics"
                        ]
                },
                {
                        "name" : "Nginx",
                        "confidence" : "100",
                        "version" : "",
                        "icon" : "Nginx.svg",
                        "website" : "http://nginx.org/en",
                        "categories" : [
                                "Web Servers"
                        ]
                },
                {
                        "name" : "Optimizely",
                        "confidence" : "100",
                        "version" : "",
                        "icon" : "Optimizely.png",
                        "website" : "http://optimizely.com",
                        "categories" : [
                                "Analytics"
                        ]
                },
                {
                        "name" : "Sizmek",
                        "confidence" : "100",
                        "version" : "",
                        "icon" : "Sizmek.png",
                        "website" : "http://sizmek.com",
                        "categories" : [
                                "Advertising Networks"
                        ]
                },
                {
                        "name" : "Twitter Bootstrap",
                        "confidence" : "100",
                        "version" : "",
                        "icon" : "Twitter Bootstrap.png",
                        "website" : "http://getbootstrap.com",
                        "categories" : [
                                "Web Frameworks"
                        ]
                },
                {
                        "name" : "VideoJS",
                        "confidence" : "100",
                        "version" : "",
                        "icon" : "VideoJS.png",
                        "website" : "http://videojs.com",
                        "categories" : [
                                "Video Players"
                        ]
                },
                {
                        "name" : "jQuery",
                        "confidence" : "100",
                        "version" : "",
                        "icon" : "jQuery.svg",
                        "website" : "http://jquery.com",
                        "categories" : [
                                "JavaScript Frameworks"
                        ]
                }
        ],
        "originalUrl" : "http://www.opencolleges.edu.au",
        "updatedAt" : ISODate("2017-07-26T23:23:19.756Z"),
        "__v" : 0,
        "createdAt" : ISODate("2017-07-24T10:37:50.247Z")
}

在我使用的.pug文件中:

ul.list-group
            each tech, i in techs
                    li.list-group-item
                        h5 #{tech.originalUrl}
                        h5 #{tech.applications.name}

然而,tech.applications.name的结果返回null值,当我使用tech.applications时它返回[Object,Object]是否可以使用PUG访问它?

0 个答案:

没有答案