用车把和猫鼬为每个数组制作模板

时间:2019-06-07 16:46:44

标签: node.js express mongoose handlebars.js

我尝试使用Mongoose和Handlebars显示结果,但不能。这是结构和“结果”数组构造异常的事实吗? 我希望每个对象都显示在页面中。 数据库示例:

{
    "objectID": 10202,
    "cars_getroute": "alfa-romeo-giulia-sprint-gt-veloce-bertone-coupe-1965-1967",
    "gm_url": "https://www.url.com",
    "results": [
        {
            "marque": "Alfa",
            "model": "Romeo Giulia Sprint GT Veloce 1600",
            "model_year": "1966",
            "price_str": "€49 280",
            "price_int": 49280,
            "price_currency": "€",
            "sold": true,
            "auction_house": "RM Sotheby's",
            "auction_country": "Italie",
            "auction_date": "25-27 novembre 2016",
            "auction_datetime": "2016-11-27",
            "auction_url": null,
            "image_urls": "https://www.url.com",
            "price_int_eu": 49280
        },
        {
            "marque": "Alfa",
            "model": "Romeo Giulia Sprint GT Veloce Coupe",
            "model_year": "1966",
            "price_str": "€46 000",
            "price_int": 46000,
            "price_currency": "€",
            "sold": true,
            "auction_house": "Bonhams",
            "auction_country": "France",
            "auction_date": "6 février 2014",
            "auction_datetime": "2014-02-06",
            "auction_url": "https://www.url.com",
            "image_urls": "https://www.url.com",
            "price_int_eu": 46000
        }
    ]
}

我的模式:

    const mongoose = require('mongoose');
const Schema = mongoose.Schema;

//Create Schema
const DemocarauctionSchema = new Schema({
    objectID: {
        type: Number
    },
    cars_getroute: {
        type: String
    },
    gm_url: {
        type: String
    },
    "results": { type: [{
        marque: {
            type: String
        },
        model: {
            type: String
        },
        model_year: {
            type: String
        },
        price_str: {
            type: String
        },
        prince_int: {
            type: Number
        },
        price_currency: {
            type: String
        },
        sold: {
            type: Boolean
        },
        auction_house: {
            type: String
        },
        auction_country: {
            type: String
        },
        auction_date: {
            type: String
        },
        auction_datetime: {
            type: String
        },
        auction_url: {
            type: String
        },
        image_urls: {
            type: String
        },
        price_int_eu: {
            type: Number
        },
    }]}

},
    {
        collection: 'democarficheauction'
    });

mongoose.model('democarauctions', DemocarauctionSchema);

我想显示每个结果,但是不起作用。

我的HTML:

<div class="results__container--box">
            {{#each results}}
                {{this}}
            {{else}}
                Aucun résultat d'enchères n'est disponible pour ce modèle.
            {{/each}}
        </div>

和Express代码:

res.render('demo/fichecar-demo', {
            results: democarauctions.results

        });

0 个答案:

没有答案
相关问题