博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[RxJS] Filtering operators: take, first, skip
阅读量:4668 次
发布时间:2019-06-09

本文共 1327 字,大约阅读时间需要 4 分钟。

There are more operators in the filtering category besides filter(). This lesson will teach how take(), first(), and skip() are simply operators to ignore or pass a certain amount of events from the source Observable.

 

 take(number):
var foo = Rx.Observable.interval(100);/*--0--1--2--3--4--5--6--7-         take(5)--0--1--2--3--4*/var bar = foo.take(5);bar.subscribe(  function (x) { console.log('next ' + x); },  function (err) { console.log('error ' + err); },  function () { console.log('done'); },);  /**  "next 0""next 1""next 2""next 3""next 4""done"  */

 

first():

var foo = Rx.Observable.interval(100);/*--0--1--2--3--4--5--6--7-         first()--0*/var bar = foo.first();bar.subscribe(  function (x) { console.log('next ' + x); },  function (err) { console.log('error ' + err); },  function () { console.log('done'); },);  /**  "next 0""done"  */

 

skip(number): different with take(), it skip the first number of item, and show the rest:

var foo = Rx.Observable.interval(100);/*--0--1--2--3--4--5--6--7    skip(5).take(3)-----------------5--6--7*/var bar = foo.skip(5).take(3);bar.subscribe(  function (x) { console.log('next ' + x); },  function (err) { console.log('error ' + err); },  function () { console.log('done'); },);  /**  "next 5""next 6""next 7""done"  */

 

转载于:https://www.cnblogs.com/Answer1215/p/5527566.html

你可能感兴趣的文章
回文日期(NOIP2016 普及组第二题)
查看>>
[jQuery]回到顶部
查看>>
用Github做一个静态网页(GithubPages)
查看>>
Win7下修改Hosts文件
查看>>
Linq to sql并发与事务
查看>>
2017-06-27
查看>>
Convert DataTable to Html Table
查看>>
JavaEE复习三
查看>>
全局ajax事件
查看>>
javascript二维数组
查看>>
JavaScript 字符串属性和方法
查看>>
opencv新手注意
查看>>
Source InSight context 窗口丢失的解决办法
查看>>
cut point and bridge总结
查看>>
(5)Oracle基础--约束
查看>>
vmware vcenter orchestrator configuration提示“用户名密码错误或登录失败超过次数被锁定”...
查看>>
【Nginx】磁盘文件写入飞地发
查看>>
默认情况下安装的应用程序C盘后提示权限不足,当你开始介意。。。
查看>>
su root 后还是不能使用useradd ,useradd 等命令
查看>>
URL.createObjectURL图片预览
查看>>