我希望将所有项目都放在findAll()
的{{1}}函数中,但它似乎不能在函数外工作......
SequelizeJS

编辑#2
我尝试创建一个包含我可以在每个视图上获取的所有链接的对象,而不是在每个操作上调用var myProjects;
Project.findAll().then(function(projects) {
myProjects = projects;
});
console.log(myProjects); // it doesn't work
... findAll()
就是一个例子,但真实的背景在我链接的模型上!
projects

var dbContext = require('./../../db/DbContext');
var _ = require('lodash');
var LinkDao = function () {
this.context = dbContext.entities;
};
_.extend(LinkDao.prototype, {
getAllByOrder: function (callback) {
return this.context.Link.findAll({order: 'position ASC', include: [{ model: this.context.Link}], where: {type: [0,1]}});
},
});
module.exports = LinkDao;

exports.locals = function(app){
app.use(function(request, response, next){
var linkDao = new LinkDao();
linkDao.getAllByOrder().success( function(links){
response.locals.navLinks = links;
});
var ecCategoryDao = new EcCategoryDao();
ecCategoryDao.getAll().success( function(ecCategories) {
response.locals.ecCategories = ecCategories;
next(); // navLinks is not accessible
});
});
};