Kendo UI 网格将 JSON 对象显示为 [object 对象]

Kendo UI Grid Showing JSON Object as [object Object]

我正在将函数传递给 fetch 方法中的 Kendo 网格字段之一。函数return在console.log上完美,然而在Kendo Grid中,只有[object Object]是return.

情况是这样的。我目前正在使用两种服务:
1.评论服务
2. 用户服务
Kendo 网格中的数据是 return 使用 ReviewService。其中一个数据是"id"。我创建了一个函数来根据 "id" 从 UserService 中找到 username。所以,我在fetch方法中使用了函数。

获取方法

protected fetch(state: any): Observable<GridDataResult> {
    this.loading = true;
    this.pagination = new Pagination(state.skip, state.take);

  return this.ReviewService.getByCriteria(this.pagination, this.apiVisa)
    .pipe(
      map(
        response =>
          <GridDataResult>{
            data: response["objectList"].map(review => ({
              id: review.id,
              email: this.displayUser(review.id)
            })),
            total: response["totalRecords"]
          }
      ),
      tap(() => (this.loading = false))
    );
  }

函数

public getUser(value): Observable<any> {
  return this.UserService.getByGuid(value, this.apiVisa);
}

public displayUser(id) {
    console.log("GUID: ", id);
    return this.getUser(id)
      .pipe(
      map((x: any) => 
        x.data
      ))
      .subscribe(x => {
        this.getItem = x.username;
        // return this.getItem;
        console.log("Username: ", x.username);
        return x.username;
        // return this.getItem;
      })
  }

预期结果
在 Kendo 网格中:Adibah
在console.log:阿迪巴

实际结果
在 Kendo 网格中:[对象对象]
在console.log:阿迪巴

在您的 displayUser 方法中,您 return 一个 Subscription 而不是实际的 x.username。您不能只 return .subscribe 中的函数来传递它的值。您可以使用 combineLatest 运算符等待第二个 observable 完成。

因此您必须从 displayUser 中删除 .subscribe 并将 combineLatest 链接到 getByCriteria 的管道