我的模特是:
var mongoose = require("mongoose");
var invoice = new mongoose.Schema({
invoiceDate: String,
invoiceNumber: String,
orderInfo: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "order"
}
],
customerInfo: [{
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "customer"
},
customerName: String,
}]
});
//EXPORT
module.exports = mongoose.model("invoice", invoice);
我希望以这种方式显示数据:
<tbody>
<%data.forEach(function(data){%>
<tr>
<td><a href="/showInvoice/<%=data._id%></td>
<td>
<%=data._id%>
</td>
<td>
<%=data.invoiceDate%>
</td>
<td>
<%=data.invoiceNumber%>
</td>
<td>
<%=data.customerInfo.customerName%>
</td>
</tr>
<%});%>
</tbody>
但我收到的错误是:
不能使用未定义的属性customerName
这很奇怪因为<%=data.customerInfo%>
有效并向我展示了一个对象,但我只需要customerName
属性。