Javascript 在字符串数组中填充接口信息(以6为单位)
我需要用接口信息填充字符串数组 我使用以下代码发送服务器请求返回角色列表:Javascript 在字符串数组中填充接口信息(以6为单位),javascript,angular,typescript,angular6,Javascript,Angular,Typescript,Angular6,我需要用接口信息填充字符串数组 我使用以下代码发送服务器请求返回角色列表: public GetRoleClaim(id:number):Observable<string[]>{ return this.http.get<string[]>('https://localhost:44390/api/Role/GetRoleClaims/'+id,{headers: this.headers}).pipe( tap(Claims => this.
public GetRoleClaim(id:number):Observable<string[]>{
return this.http.get<string[]>('https://localhost:44390/api/Role/GetRoleClaims/'+id,{headers: this.headers}).pipe(
tap(Claims => this.log("fetch claims")),
catchError(this.handleError('Error GetRoleClaim', []))
);
}
。现在我需要填充这个变量selectedRole:string[]代码>带有索赔值
claimValue
从服务器接收
我该怎么做 首先,this.claims
应该是一个声明数组,因为代码中的数据
变量也是一个声明数组。
如果在.ts
文件中全局定义了“claims”变量定义,则该变量定义将如下所示
claims: Claims[] = [];
现在,您可以编写一个for循环来填充selectedRole
变量
for (const value of this.claims) {
selectedRole.push(value.claimValue);
}
假设selectedRole是在本地定义的。如果是全局定义的,则上述代码如下所示:
for (const value of this.claims) {
this.selectedRole.push(value.claimValue);
}
for (const value of this.claims) {
this.selectedRole.push(value.claimValue);
}