0

在 Rxjs5 中找不到 Rx.Observable.pairs,我只需将对象转换为 Observable 并检查每个属性的更改。有任何想法吗?

 var a = { aa: "aa", bb: "bb" };
   function pairs(obj) {
    // List of object's key-value pairs
    var keyValuePairs = Object.keys(obj).map(key => ({ key, value: obj[key] }));
    // Convert to an Observable and return
    return Rx.Observable.from(keyValuePairs);
    }

  var xxx = pairs(a);
xxx.subscribe(x => {
    console.log(x);
})

a.aa = "mm";
4

1 回答 1

0

您可以从头开始完成此操作:

function pairs(obj) {
    // List of object's key-value pairs
    var keyValuePairs = Object.keys(obj).map(key => ({ key, value: obj[key]}));

    // Convert to an Observable and return
    return Rx.Observable.from(keyValuePairs);
}
于 2016-03-17T15:14:25.843 回答