使用Sequelize将两个模型发送到视图

我试图用Sequelize发送两个模型到一个视图,但我不知道如何继续。

我下面的代码不起作用。

Post.findAll().success( function(posts) { Creation.findAll().success( function(creations) { res.render('admin_index', { creations: creations, posts: posts }); }); }); 

安东尼

其实你没有回传你的callback任何职位,这就是为什么职位未定义。

所以你不能在yoru res.render上下文中访问它。

检查你的callback的这一部分

  Creation.findAll().success( function(creations) { // The other stuff }); 

在这里,你只是返回创build,而不是你应该写一个查询返回创build和post。 或者在callback链中进行多个查询。

  RandomQuery.findAll().success( function(creations,posts) { // The other stuff }); 

或者将callback链接在一起

  Creation.findAll().success( function(creations) { Post.findAll().success(function(posts){ res.render('admin_index', { creations: creations, posts: posts }); }); });