简体   繁体   English

RxJs可通过拉动来观察

[英]RxJs Observable from backed with pulling

I'm quite new to RxJs (and not that good in js ) and have a hard time finding how I can write Rx equivalent of 我对RxJ相当陌生(在js中不是那么好),很难找到如何写与

var arr = [];

var getData = function () {
    $.get("/newlines", {}, function (data) {
        data.push.apply(arr, data);
        setTimeout(getData, 1000);
        console.log(arr);

    },'json');

};

setTimeout(getData, 1000);

What I'm thinking about is to Observable which will produce items from async callbacks. 我在想的是Observable,它将从异步回调中产生项目。

var arr = [];
Rx.Observable.interval(1000)
    .selectMany(Rx.Observable.fromPromise($.get("/newlines", {})))
    .subscribe(function(data) {        
        data.push.apply(arr, data);
        console.log(arr);
});

Typed on my Smartphone thus untested. 在我的智能手机上输入,因此未经测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM