使用RxJs我试图重现一个演示.但我没有得到任何结果.而是将错误视为:distinct.flatMapLatest is not a function
我在这做错了什么?我需要在library这里添加吗?
这是我的尝试:但是看一下demo来获得真正的问题是什么面孔.
$(document).ready(function(){
var $input = $('#input'),
    $results = $('#results');
var keyups = Rx.Observable.fromEvent($input, 'keyup')
    .map(e => e.target.value)
    .filter(text => text.length > 2);
var throttled = keyups.throttle(500);
var distinct = throttled.distinctUntilChanged();
function searchWikipedia (term) {
    return $.ajax({
        url: 'http://en.wikipedia.org/w/api.php',
        dataType: 'jsonp',
        data: {
            action: 'opensearch',
            format: 'json',
            search: term
        } 
    }).promise();
}
var suggestions = distinct.flatMapLatest(searchWikipedia);
suggestions.subscribe(data => {
    var res = data[1];
    /* Do something with the data like binding */
    $results.empty();
    $.each(res, (_, value) => $('<li>' + value + '</li>').appendTo($results));
}, error => {
    /* handle any errors */
    $results.empty();
    $('<li>Error: ' + error + '</li>').appendTo($results);
});
})
m59*_*m59 21
在RxJS 5中,flatMapLatest已重命名为switchMap.
var suggestions = distinct.switchMap(searchWikipedia);