jsp - BootStrap/ JQuery Call method on page load or render -


i attempting sort list of programs, "checked" or included programs listed first. however, having hard time bootstrap , getting method call when page loads. .jsp file , utilizing backbone , bootstrap.

here existing function works fine, if sort button clicked.

onsortcheckedclick : function(e) { e.preventdefault(); var anchor = $(e.currenttarget);

            var li = anchor.parent("li.sortchecked");             if (li.hasclass("active")) {                 return;             }              var sortdirectionorder = anchor.attr("data-direction");             var sortdirectioncolumn = anchor.attr("data-sortbycheck");             var attributesnames = sortdirectioncolumn.split('.');              var sortedprograms = this.programs.sortby(function(program) {                 var answers = program.tojson();                  var unchecked = new array();                  var selectanswers, unselectanswers;                 if(answers.selected === true){                     selectanswers = answers;                 }else if(answers.selected === false){                     unselectanswers = answers;                 }                  return unselectanswers;             });              if (sortdirectionorder === 'asc') {                 sortedprograms.reverse();             }              this.$("thead li.sortchecked").removeclass("active");             li.addclass("active");             this.programs.reset(sortedprograms);         }, 

and here registered event listeners. best way of going calling method above when list of programs rendered?

thanks!

you can call function once page rendered.

$(document).ready(function(){ //call function here //it assumed list of programs rendered on page load //-- otherwise -- // call renderprogram() , call or add event listeners onsortcheckedclick() }); 

you can use jquery deferred object handle call of onsortcheckedclick after renderprogram() has been finished.

call ready function on main html file (or include in main html file).


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -