最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

从getter方法中继续返回值

IT培训 admin 2浏览 0评论

从getter方法中继续返回值

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

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

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

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

<%= event.awayTeamName %>
回答如下:

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

从getter方法中继续返回值

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

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

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

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

<%= event.awayTeamName %>
回答如下:

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

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论