2013-02-14 43 views
3

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

我的下面的代码不起作用。

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

安东尼

+0

做u体验到什么问题的回调? – sdepold 2013-02-14 07:57:28

+0

在我的视图“admin_index”中无法识别数组“帖子”... – tonymx227 2013-02-14 07:59:15

回答

3

其实你的arent在回调返回任何职位,这就是为什么职位是不确定的。

这样你就不能在yoru res.render上下文中访问它。

检查你的回调

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

在这里,你只返回创作,而不是你应该写一个返回两个创作和职位查询的这个部分。或者在回调链中做多个查询,就像这样。

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

或链条内相互

Creation.findAll().success(function(creations) { 
    Post.findAll().success(function(posts){ 

     res.render('admin_index', { 
      creations: creations, 
      posts: posts 
     }); 

    }); 
}); 
+0

谢谢,它的工作原理!我忘了切换“创作”和“帖子”。 – tonymx227 2013-02-14 09:10:25

相关问题