静态网页已经成为历史,如今的web设计趋势是预测客户想法并提供更好的互动功能,例如自动填写表单、搜索WikipeDia等。RxJS框架可以很方便地为鼠标和键盘事件提供响应。
示例代码:
var $input = $('#input'), $results = $('#results'); /* Only get the value from each key up */ var keyups = Rx.Observable.fromEvent(input, 'keyup') .map(Function (e) { return e.target.value; }) .filter(function (text) { return text.length > 2; }); /* Now throttle/debounce the input for 500ms */ var throttled = keyups .throttle(500 /* ms */); /* Now get only distinct values, so we eliMINAte the arrows and other control characters */ var distinct = keyups .distinctUntilChanged();
发布于 2016-01-15 00:05:09 | 610 次阅读