🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## Join 任何时候,只要在另一个Observable发射的数据定义的时间窗口内,这个Observable发射了一条数据,就结合两个Observable发射的数据。 ![join](https://box.kancloud.cn/8f490a3189fb8e2c327ee6a133fa5b37_1280x760.png) `Join`操作符结合两个Observable发射的数据,基于时间窗口(你定义的针对每条数据特定的原则)选择待集合的数据项。你将这些时间窗口实现为一些Observables,它们的生命周期从任何一条Observable发射的每一条数据开始。当这个定义时间窗口的Observable发射了一条数据或者完成时,与这条数据关联的窗口也会关闭。只要这条数据的窗口是打开的,它将继续结合其它Observable发射的任何数据项。你定义一个用于结合数据的函数。 ![groupJoin](https://box.kancloud.cn/14ef94f38c31348dbd69f8acd3710a77_1280x760.png) 很多ReactiveX实现还有一个类似的`GroupJoin`操作符。 Most ReactiveX implementations that have a Join operator also have a GroupJoin operator that is similar, except that the function you define to combine items emitted by the two Observables pairs individual items emitted by the source Observable not with an item from the second Observable, but with an Observable that emits items from the second Observable that fall in the same window. ![join](https://box.kancloud.cn/3735151ef6b57c2619ee48c5c396d1f1_1280x760.png) The `join` operator takes four parameters: 1. the second Observable to combine with the source Observable 2. a function that accepts an item from the source Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the second Observable 3. a function that accepts an item from the second Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the first Observable 4. a function that accepts an item from the first Observable and an item from the second Observable and returns an item to be emitted by the Observable returned from join `join`默认不在任何特定的调度器上执行。 * Javadoc: [Join(Observable,Func1,Func1,Func2)](http://reactivex.io/RxJava/javadoc/rx/Observable.html#join(rx.Observable,%20rx.functions.Func1,%20rx.functions.Func1,%20rx.functions.Func2)) ![groupJoin](https://box.kancloud.cn/00787e6428078c2306066cc44b95b1fb_1280x760.png) The `groupJoin` operator takes four parameters: 1. the second Observable to combine with the source Observable 2. a function that accepts an item from the source Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the second Observable 3. a function that accepts an item from the second Observable and returns an Observable whose lifespan governs the duration during which that item will combine with items from the first Observable 4. a function that accepts an item from the first Observable and an Observable that emits items from the second Observable and returns an item to be emitted by the Observable returned from groupJoin `groupJoin `默认不在任何特定的调度器上执行。 * Javadoc: [groupJoin(Observable,Func1,Func1,Func2)](http://reactivex.io/RxJava/javadoc/rx/Observable.html#groupJoin(rx.Observable,%20rx.functions.Func1,%20rx.functions.Func1,%20rx.functions.Func2)) ![st.join](https://box.kancloud.cn/ed59e87511a41fe1df175d9948b258b6_1280x590.png) 可选的`StringObservable`类中也有一个`join`操作符。它将一个发射字符串序列的Observable转换为一个发射单个字符串的Observable,`join`操作符使用指定的定界符将全部单独的字符串连接起来。