javascript - On change event on the selection of dropdown's value using underscore and backbone -
i created dynamic dropdown in template. , further requirement change value of dropdown , send value web service hit change in system. have no idea how in underscore template. below code write dynamic dropdown. , have write ratecall function either in template file or in main.js no idea it. , rightnow firing alert showing on change fired not working. error coming ratecall not defined. appreciated. in advance.
<select id="rate" onchange="ratecall()"> <% for(var i=0;i<post.scales-1;i++){ if(i==post.rated){ var a= 'selected'; }else{ a=''; } %> <option id="<%=i%>"<%=a %> > <%= i%></option> <%}%> </select> <%}else{ } function ratecall(){ document.getelementbyid("rate").onchange = function () { alert("on change fired"); }; }
as pointed @danblundell in comments, view should responsible rendering. made minimal backbone example illustrates how it's done (for example): http://jsfiddle.net/dh64x/3/
backbone provides view objects can specify events , event handlers:
var postview = backbone.view.extend({ events: { 'change #rate': 'postselected' }, // ... postselected: function(e) { console.log(e); } });
in case, change events on select#rate element bound postselected
function.
read docu more details: http://backbonejs.org/#view
Comments
Post a Comment