为什么我的静态方法值没有出现在我的ejs页面



这是来自模型

    static status(){
      this.count()
        .then(data => {
          return data;
        })
    }

我想把static status()的值放到我的ejs页面

这个在我的控制器中但是当我运行代码时这个值没有出现

static home(req, res){
    // console.log(req.query);
    let title = req.query.title;
    let artist = req.query.artist;
    let temp = {};
    if(title){
      temp.name = {[Op.iLike]: '%' + title + '%'}
    }else{
      temp.name = {[Op.iLike]: '%' + '%'}
    }
    if(artist){
      temp.artist = {[Op.iLike]: '%' + artist + '%'};
    }else{
      temp.artist = {[Op.iLike]: '%' + '%'}
    }
    // console.log(temp);
    Art.findAll({
      order: [['date', 'desc']], 
      where: {name: temp.name, artist: temp.artist}
    })
      .then(data => {
        // console.log(data[0])
        res.render('home', {
          data,
          Art,
        });
      })
      .catch(err => {
        res.send(err);
      })
  }

这是在我的ejs页面<%= Art.status() %>

status中,您不会从异步count调用返回值,您最好将此函数标记为异步,并简单地从count返回值:

async static status(){
  return this.count()
}

最新更新