2017-10-17 144 views
-2

我有一个函数,其中包含一个对象数组,并且希望将它们与.esj/.htlm页面(尽管我假设为数据变量)一起使用。这是我的,不知道如何去做这个,谢谢!设置Express/EJS服务器

app.get('/', (req, res) => { 
// want to get the data in here 
res.render('index', data); 
}) 

回答

0

看起来像你还没有学习的基础知识。 您可以通过以下方式执行此操作:

app.get('/', (req, res) => { 
     // call your function here 
     //normal sync function 
     data=function_name() 
     res.render('index', data); 

     //if you are using promisified function 
     function_name() 
     .then(data => { 
      res.render('index', data); 
     }).catch(error => { 
      console.log(error) 
      res.send(error) 
     }) 
    })