我想将一些已分页的数据从 REST API 加载到我的 Angular 应用程序中。通常,API 会按照以下结构向我发送数据:
{
"next": null,
"results": [
{"id": 7, "name": "Alicia"},
{"id": 8, "name": "Ted"},
{"id": 9, "name": "Marshall"}
]
}
Run Code Online (Sandbox Code Playgroud)
哪里next是下一个数据页请求的 url GET/。显然,我事先并不知道需要迭代多少页才能完全加载数据。
我编写了以下工作代码以便完全获取数据(此处为工作plunker):
public loadPeople( next?:string ): void {
if(!next) next = 'api/1.json';
this.http.get(next)
.pipe(
map( (response: Response) => response.json())
)
.subscribe( (data: any) => {
this._people = this._people.concat(data.results);
this._peopleSubject.next(this._people);
if(data.next) this.loadPeople(data.next);
})
}
Run Code Online (Sandbox Code Playgroud)
然而,我确实缺乏 Rx.JS 的经验,并且我很确定有一种更好、更干净的方法来做到这一点,通过Observables使用运算符进行链接,但我无法亲自动手。
我可以使用一个运算符吗?谢谢 !
我不断接收和存储未压缩JSON 对象的多个源,按天分区到 Amazon S3 存储桶的不同位置(配置单元样式:)s3://bucket/object=<object>/year=<year>/month=<month>/day=<day>/object_001.json,并计划使用 AWS 增量批处理这些数据并将其加载到 Parquet 数据湖胶水:
这种设计模式和架构似乎是一种相当安全的方法,因为它得到了许多 AWS博客的支持。
我有一个爬虫配置如下:
{
"Name": "my-json-crawler",
"Targets": {
"CatalogTargets": [
{
"DatabaseName": "my-json-db",
"Tables": [
"some-partitionned-json-in-s3-1",
"some-partitionned-json-in-s3-2",
...
]
}
]
},
"SchemaChangePolicy": {
"UpdateBehavior": "UPDATE_IN_DATABASE",
"DeleteBehavior": "LOG"
},
"Configuration": "{\"Version\":1.0,\"Grouping\":{\"TableGroupingPolicy\":\"CombineCompatibleSchemas\"}}"
}
Run Code Online (Sandbox Code Playgroud)
每个表都是“手动”初始化的,如下所示:
{
"Name": "some-partitionned-json-in-s3-1",
"DatabaseName": "my-json-db",
"StorageDescriptor": {
"Columns": [] # i'd like the crawler to figure this out …Run Code Online (Sandbox Code Playgroud) 问题可能听起来很愚蠢(因为我相信答案是显而易见的)...但我正在尝试将CSS类绑定foo到我的主机组件,使用@HostBinding,取决于我对动态变量的测试.但无法使其正常工作.这是我已经尝试过的(代码基本上说明了我正在尝试做的事情):
export class MyComponent {
@Input()
public input: string;
@HostBinding('class.foo')
public isFoo: Boolean = this.inputIsCorrect();
constructor() {
}
private inputIsCorrect(){
return (this.input != 'not correct');
}
}
Run Code Online (Sandbox Code Playgroud)
知道我怎么能让它工作吗?我可能正在考虑听取input变化的方式?
谢谢你的帮助 !