【问题标题】:Json Object PropertyJson 对象属性
【发布时间】:2021-03-12 12:04:21
【问题描述】:

我只想解析标题。我使用了 express、body-parse 和 pug。这是我的代码:

router.get('/', async (req, res) => {

   try {
       const posts = await Post.find()
       res.render('post', {title: posts })
   }
   catch (err){
       res.json({errors:err})
   }
})

[][1]



  [1]: https://i.stack.imgur.com/1Qa1m.png

【问题讨论】:

    标签: node.js json express object pug


    【解决方案1】:
    try {
        let posts = await Post.find()
        posts = posts.pop()
        res.render('post', {title: posts['title'], description: posts['description']} )
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-08
      • 1970-01-01
      • 2020-02-02
      • 2012-08-26
      • 1970-01-01
      • 2015-09-21
      • 2012-12-04
      • 2014-06-26
      相关资源
      最近更新 更多