Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<select>
  <option selected hidden> -- select ID -- </option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>
<div id="result"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.4.0/Rx.js"></script>
 
const select = document.querySelector('select');
const result = document.getElementById('result');
const id$ = Rx.Observable.fromEvent(select, 'change').map(e => e.target.value);
const fetchPost = id => {
  const url = `https://jsonplaceholder.typicode.com/posts/${id}`;
  return Rx.Observable.ajax(url).map(res => res.response);
};
const render = post => {
  result.innerHTML = post.title;
};
id$.switchMap(fetchPost).subscribe(render);
Output

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers