【问题标题】:Kendo UI Grid Showing JSON Object as [object Object]Kendo UI Grid 将 JSON 对象显示为 [object Object]
【发布时间】:2019-01-27 04:39:05
【问题描述】:

我正在将一个函数传递给 fetch 方法中的 Kendo Grid 字段之一。该函数在 console.log 上完美返回,但在 Kendo Grid 中,仅返回 [object Object]。

情况是这样的。我目前正在使用两种服务:
1. 评论服务
2. 用户服务
Kendo Grid 中的数据是使用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;
      })
  }

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

实际结果
在剑道网格中:[object Object]
在 console.log 中:Adibah

【问题讨论】:

    标签: angular typescript kendo-grid


    【解决方案1】:

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

    所以你必须从displayUser 中删除.subscribe 并将combineLatest 链接到getByCriteria 的管道

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-30
      • 1970-01-01
      • 1970-01-01
      • 2013-12-24
      相关资源
      最近更新 更多