javascript - Backbone js router - better way to orginize views -


here way orginize 4 views , 4 links backbone router

var linksrouter = backbone.router.extend({     routes:{         "classes" : "classes",         "profile" : "profile",         "reportcard" : "reportcard",         "newclasses" : "newclasses",     },     classes : function(){         $(".viewable").hide();         $(".clickable").removeclass("active");         $("#classes-view").show();               $("#classes-link").addclass("active");                                       },     profile : function(){         $(".viewable").hide();         $(".clickable").removeclass("active");         $("#profile-view").show();               $("#profile-link").addclass("active");                                       },     reportcard : function(){         $(".viewable").hide();         $(".clickable").removeclass("active");         $("#reportcard-view").show();                $("#reportcard-link").addclass("active");                                        },     newclasses : function(){         $(".viewable").hide();         $(".clickable").removeclass("active");         $("#newclasses-view").show();                $("#newclasseslink").addclass("active");                                         }                        }); var links = new linksrouter(); backbone.history.start(); 

it looks tedious , not efficient. there better way backbone js?

i'm sure there many ways.. how about:

var linksrouter = backbone.router.extend({     routes:{         ":subview" : "viewset",  // or "/:subview" ?     },     viewset : function(subview){         $(".viewable").hide();         $(".clickable").removeclass("active");         $("#"+subview+"-view").show();               $("#"+subview+"-link").addclass("active");                                       } }); var links = new linksrouter(); backbone.history.start(); 

Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -