为什么我的静态方法值未出现在我的EJS页面中

发布于 2025-01-21 16:40:48 字数 986 浏览 2 评论 0原文

模型

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

这是从我想将静态状态()值的

我的控制器中

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()%>

this is from the models

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

I wanna take the value of static status() to my ejs page

this is in my controller but when i run the code the value didn't appear

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);
      })
  }

this is in my ejs page
<%= Art.status() %>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绿光 2025-01-28 16:40:48

状态中,您不会从异步count调用返回值,您最好将此函数标记为异步:

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

In status you don't return a value from an async count call, you better mark this function as async and simply return value right from count:

async static status(){
  return this.count()
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文