我是node.js的新手,正在学习中使用getting MEAN with Mongo, Express..。返回使用邮递员测试数据。但是,当使用api时我不知道会发生什么。查看的渲染页面变为空白,没有数据渲染。所使用的功能参数如上述参考书中所写。代码段如下所示。 location.js
var renderhomePage = function (req, res, responseBody) {
res.render('index',{
title1: 'Bromitzvah',
pageSection1: {
title1: 'This Is Important',
content1: 'Duis neque nisi, dapibus sed mattis et quis, nibh. Sed et dapibus nisl amet mattis, sed a rutrum accumsan sed. Suspendisse eu.',
title2 : 'Another one',
content2 : 'Duis neque nisi, dapibus sed mattis et quis, nibh. Sed et dapibus nisl amet mattis, sed a rutrum accumsan sed. Suspendisse eu.',
title3 :'Probably Important',
content3 : 'Duis neque nisi, dapibus sed mattis et quis, nibh. Sed et dapibus nisl amet mattis, sed a rutrum accumsan sed. Suspendisse eu.',
},
post1: responseBody });
};
module.exports.homelist = function (req,res) {
var requestOptions,path;
path = '/api/home';
requestOptions = {
url: apiOptions + path,
method: "GET",
json: {},
};
request(requestOptions,function (err, response, body) {
renderhomePage(req, res, body);
} );
};
mongodb收集代码段如下所示
"_id" : ObjectId("5b9bff5e14fa7de5a113e765"), "title1" : "Bromitzvah", "post1" : [ { "title" : "The First Thing", "content" : "Duis neque nisi, dapibus sed mattis et quis, nibh." }, { "title" : "The Second Thing", "content" : "Duis neque nisi, dapibus sed mattis et quis, nibh." } ]
我的架构如下
var mongoose = require('mongoose');
var pageSectionSchema = new mongoose.Schema({
title1: String,
content1: String,
title2: String,
content2: String,
title3: String,
content3: String,
});
var post1Schema = new mongoose.Schema({
title: String,
content: String,
});
var post2Schema = new mongoose.Schema({
title: String,
content: String,
});
var locationSchema = new mongoose.Schema({
title1: String,
pageSection1:[pageSectionSchema],
post1:[post1Schema],
post2:[post2Schema],
});
mongoose.model('Location',locationSchema);
有人可以帮助我吗?