i doing fromevent on click observable, however, want data attribute element gave event. i'been trying use within no success. how can achieve normal 'this' jquery
var elem = $(".someelementclass"); var source = rx.observable.fromevent(elem, 'click'); var subscription = source.subscribe(function (e) { var x = $(this).attr("data-toget"); alert(x); });
this
inside callback not refer jquery
object, example in $.each
., in case can use $(e.currenttarget)
instead of $(this)
var elem = $(".someelementclass"); var source = rx.observable.fromevent(elem, 'click'); var subscription = source.subscribe(function (e) { console.log($(e.currenttarget).attr("data-toget")); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script src="https://npmcdn.com/@reactivex/rxjs@5.0.0-beta.7/dist/global/rx.umd.js"></script> <button class="someelementclass" data-toget="100">button-1</button> <button class="someelementclass" data-toget="200">button-2</button> <button class="someelementclass" data-toget="300">button-3</button>
Comments
Post a Comment