我正在尝试创建一个列表来显示数据库中的所有teams
。我收到错误TypeError: Invalid select() argument. Must be a string or object.
任何人都可以帮我弄清楚如何解决这个问题?我只是想用它来打印当前团队的列表,然后可以点击这个团队列表来编辑团队名称!
所以在我的Schema
Team
我有这个:
Team.statics.getAllMeta = function(cb){
var query = this.find({}, ['key', 'name'], cb);
return query.exec(cb);
};
然后在我的index.js
routes
我有这个:
var getAllMeta = function(req, res, next){
Team.getAllMeta(function(err, teamsList){
if(!err && teamsList){
req.teamsList = teamsList;
}
next(err);
});
};
然后,我可以在routes
我的team
页面中调用这样的内容:
app.get('/team', getAllMeta, function(req, res){
util.log('Serving request for url[GET] ' + req.route.path);
res.render('team', {'teamsList' : req.teamsList});
});
此处仅供参考,index.js
来自routes
app.get('/', function(req, res){
logger.log('Serving request for url [GET]' + req.route.path)
Team.getAll(function(err, allTeams){
if(!err && allTeams){
res.render('index', {'allTeams' : allTeams});
}else{
util.log('Error fetching team from database : ' + err);
res.render('error');
}
});
});
app.get('/show/team/:key', function(req,res){
Team.findByKey(req.params.key, function(err, teamData){
if(!err && teamData){
teamData = teamData[0];
res.json({
'retStatus' : 'success',
'teamData' : teamData
});
} else {
util.log('Error in fetchin Team by key: ' + req.params.key);
res.json({
'retStatus' : 'failure',
'msg' : 'Error in fetching Team by key: ' + req.params.key
});
}
});
});
答案 0 :(得分:1)