从getter方法中继续返回值

问题描述 投票:1回答:1

我无法从getterMethod获取实际值。目前我有以下内容:

  getterMethods: {
      awayTeamName() {
          return this.getAwayTeam().then(function(awayTeam) {
              return awayTeam.getTeams().then(function(team) {
                  return team.name;
              });
          });
      }
  }

我的问题是,它总是将'[object Promise]'返回到视图而不是值。

我想通过'返回'所有的承诺,我最终会得到价值。在我的EJS模板中,我实际上只是将其称为:

<%= event.awayTeamName %>
javascript node.js sequelize.js
1个回答
0
投票

我的解决方案是在getterMethods之外实际抽象它,并为它创建一个新的中间件函数。我也在使用这个异步库在循环中的许多对象上设置一个新属性,然后再传回视图。

© www.soinside.com 2019 - 2024. All rights reserved.