Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何在节点中访问数组中的对象_Node.js_Schema_Ejs - Fatal编程技术网

Node.js 如何在节点中访问数组中的对象

Node.js 如何在节点中访问数组中的对象,node.js,schema,ejs,Node.js,Schema,Ejs,我正在尝试访问博客架构内的正文。我该怎么做呢 模式: ** 路由器 ** ** publishedArticle.ejs ** 我没有定义您已将您的博客架构声明为对象数组(请注意,您已将对象周围的[]用于博客项目)。如果这是有意的,那么您需要使用数组索引访问文章中的各种博客元素(或者使用循环对它们进行迭代)。下面的代码段假定您的文章至少保存了一个博客条目: <h3><%= article.blog[0].body %></h3> 谢谢,看起来很简单 ro

我正在尝试访问博客架构内的正文。我该怎么做呢

模式:

**

路由器

**

**

publishedArticle.ejs

**



我没有定义

您已将您的博客架构声明为对象数组(请注意,您已将对象周围的[]用于博客项目)。如果这是有意的,那么您需要使用数组索引访问文章中的各种博客元素(或者使用循环对它们进行迭代)。下面的代码段假定您的文章至少保存了一个博客条目:

<h3><%= article.blog[0].body %></h3>

谢谢,看起来很简单
router.get('/blog/article/:postid', function (req, res, next) {
  Article.findById({ _id: req.params.postid }, function (err, article) {
    if (err) return next(err);
    res.render('main/publishedArticle', {
      article: article,
      message: req.flash('showing article ' + article.title)
    });
  });
});
<h3><%= article.blog.body %></h3>
<h3><%= article.blog[0].body %></h3>