【问题标题】:Loop through mongoDB database arry using @foreach in express在 express 中使用 @foreach 循环遍历 mongoDB 数据库数组
【发布时间】:2019-03-16 04:44:58
【问题描述】:

您好,我有一个数据库,我可以使用

在视图中访问它

html 和 express 布局我认为@each 和 {{}} 是一种 js 语法

{{posts[0].detail}}   <----------------This works 

但我想使用

显示帖子的所有内容
@each(post in posts)

{{post[don't know what to put here].detail}}

@end 

【问题讨论】:

  • 语法@each(post in posts)是什么语言。此外,您可能必须{{post.detail}}{{posts[post].detail}}
  • 好吧,我使用 express 作为布局,使用 html 作为视图,这就是我所知道的我要尝试的帖子[post].detail
  • {{posts[post].detail}}
  • {{post.detail}} 呢?你得到什么错误?另外,我没有看到 EJS 具有 @each 语法,您确定您使用 EJS 进行模板吗?
  • @Cristy woooooooooooooooooooooooooooo 成功了,谢谢ssssssssss

标签: html node.js mongodb express


【解决方案1】:

@Cristy 的 {{post.detail}} 怎么样

所以这回答了我的问题。

我认为@each(post in posts)

现在我知道 post 具有帖子的属性。

例如:

@each(post in cars)

【讨论】:

    猜你喜欢
    • 2013-12-16
    • 2017-03-22
    • 2013-11-05
    • 2013-03-26
    • 1970-01-01
    • 1970-01-01
    • 2010-10-24
    • 2018-07-17
    相关资源
    最近更新 更多