我要求使用 gapi 谷歌驱动器:
getFolders(folderId: string): Observable<{ id: string, name: string }[]> {
const promise = gapi.client.drive.files.list({
fields: 'incompleteSearch,nextPageToken,files(id,name)',
q: `'${folderId}' in parents`,
}).then((res) => {
return JSON.parse(res.result.files);
});
return from(promise);
}
然后我尝试在组件中显示这些数据:.ts 文件ngOnInit
:
this.data$ = this.googleDriveService.getFolders(rootFolderId)
.pipe(
map((files) => {
debugger;
return files.map(file => ({ id: file.id, header: file.name, content: '', imageUrl: this.defaultImageUrl }));
}),
takeUntil(this.destroy$),
);
和 html 文件:
<mat-grid-tile *ngFor="let elem of (data$ | async)">
<app-card (input)="returnCartItem(elem)" (click)="goto(elem.header, elem.id)"></app-card>
</mat-grid-tile>
问题是data$
总是空的。我添加debugger
到map
检查那里可能有问题,但它永远不会map
发挥作用。从响应中,我得到 2 个文件,所以res.result.files
不是空的;