在数组内的对象内显示字符串

时间:2019-02-23 14:16:38

标签: javascript mongoose

JavaScript

var questionsSchema = new mongoose.Schema({
    question: String,
    Answers: [{
        answerSummary: String,
        answer: String,
        answerExtended: String,
        image: String,
        source: String,
        date: String,
    }],
});  

var question = mongoose.model("question", questionsSchema);

我想显示字符串answerSummary。我尝试了这个没有成功:

<%= question.Answers.answerSummary%>

帮助?

1 个答案:

答案 0 :(得分:0)

答案是一个数组,因此必须明确指定要获取数组的位置。  question.Answers[0].answerSummary