Backbone.js html select / radio change event is not firing, but click event is -
i learning backbone i'm stuck @ binding onchange event html option element.
i tried bind 'change' or 'change #id' none of these fire. however, both 'click' , 'click #id' event work.
<div id='target'> <select id='abc'> <option value=1>1</option> <option value=2>2</option> </select> </div> <input type='radio' name='def' value='1' checked>1</input> <input type='radio' name='def' value='2'>2</input> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script> <script> $(function () { var targetview = backbone.view.extend({ el: '#target', events: { 'click #abc': 'onclick', 'click input[name=def]': 'onclick', 'change': 'onselect', 'change input[name=def]': 'onselect', 'change #abc': 'onselect' }, onclick: function (evt) { console.log('click'); console.log($(evt.currenttarget).val()); }, onselect: function (evt) { console.log('change'); } }); new targetview(); }); </script>
i think there no way specify onchange onselect event of drop down using backbone.
the workaround use jquery directly
var view = backbone.view.extend({ initialize:function () { // on click ok this.model.on('click', this.click, this); // cannot bind using backbone events change reasons, have use jquery setup event $('input[name="my-dropdown"]', this.el).on('change', $.proxy(this.onselect, this)); } );
Comments
Post a Comment