2017-10-17 147 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) 
     }) 
    })