【发布时间】: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