这就是我的mat-paginator
样子:
<mat-paginator [pageSizeOptions]="pageSizeOptions" [length]="100"></mat-paginator>
Run Code Online (Sandbox Code Playgroud)
基本上我正在尝试实现一个典型的分页想法:服务器不返回所有数据,它返回其中的一部分,然后当打开新页面时,它会返回另一部分数据。为了做到这一点,我需要让分页器知道数据库中有多少项,也就是说,我需要向它提供 prop length
。
我尝试以多种方式设置它,直接在上面的行中或在我发出 get 请求的方法内部。像这样:
this.paginator.length = 100;
Run Code Online (Sandbox Code Playgroud)
事实上,长度应该来自服务器,但目前出于调试目的,我只是将其硬编码。
this.dataSourceService.findAll().subscribe(
records => {
this.paginator.length = 100;
this.dataSource.data = records.map(
record => new Record().deserialize(record)
)
}
)
Run Code Online (Sandbox Code Playgroud)
我在客户端上获得的长度值仍然等于我在服务器响应中获得的数组中包含的项目数。
我做错了什么以及为什么长度值没有设置为 100。
编辑:
好吧,这是一些更相关的代码。
在组件内部我执行以下操作:
dataSource = new MatTableDataSource<Record>();
pageSizeOptions: number[] = [5, 10, 20];
Run Code Online (Sandbox Code Playgroud)
里面OnInit()
我还有以下行:this.dataSource.paginator = this.paginator;
客户端向服务器发送不记名令牌,如下所示:
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
Run Code Online (Sandbox Code Playgroud)
显然我不需要“Bearer”前缀,所以我必须去掉它。我知道这就像分割字符串并获取正确的元素一样简单,但我不明白的是为什么我正在使用的库函数不为我做这件事。我还必须检查令牌是否实际上是正确的类型(在本例中是不记名的)。它迫使我编写额外的代码行,但我不喜欢它。
所以我的问题是“有没有更智能的方法来处理令牌?”
我在用着PyJWT
。
我有最基本的管道,我想在自定义提供程序的方法上使用它。管道如下所示:
@Injectable()
export class DateTransformPipe implements PipeTransform {
transform(value: any, metadata: ArgumentMetadata) {
console.log('Inside the DateTransformPipe pipe...');
return value;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我想使用它的类:
@Injectable()
export class MyProvider {
@UsePipes(new DateTransformPipe())
private getDataFor(onDate: Date): string {
console.log(onDate);
return 'Some Stuff'
}
}
Run Code Online (Sandbox Code Playgroud)
管道位于一个特殊的目录中src/helpers/pipes
。这里的问题是根本没有调用管道的变换方法......我似乎不明白为什么。
这是我要发出的查询:
const updatedUser = await queryRunner.manager
.getRepository(UserEntity)
.createQueryBuilder('user')
.leftJoinAndSelect('user.categories', 'cats')
.where('id = :userId', { userId })
.getOne();
Run Code Online (Sandbox Code Playgroud)
这是由 typeorm 生成的查询:
SELECT "user"."id" AS "user_id",
"user"."first_name" AS "user_first_name",
"user"."last_name" AS "user_last_name",
"user"."phone" AS "user_phone",
"user"."password" AS "user_password",
"user"."password_hint" AS "user_password_hint",
"user"."recovery_email" AS "user_recovery_email",
"user"."created" AS "user_created",
"user"."username" AS "user_username",
"user"."profile_pic" AS "user_profile_pic",
"user"."is2fa" AS "user_is2FA",
"user"."refresh_token" AS "user_refresh_token",
"user"."profile_email" AS "user_profile_email",
"user"."subscriptionid" AS "user_subscriptionId",
"cats"."id" AS "cats_id",
"cats"."template_id" AS "cats_template_id",
"cats"."name" AS "cats_name",
"cats"."entry_count" AS "cats_entry_count",
"cats"."is_base_template" AS "cats_is_base_template",
"cats"."can_rename" AS …
Run Code Online (Sandbox Code Playgroud) nestjs ×2
angular ×1
node.js ×1
pagination ×1
postgresql ×1
python ×1
typeorm ×1
typescript ×1