javascript - Is there a way to detect changes within the same route? -


with iron router, have following route set up:

router.route('/:cat', {     name: "goods",     waiton: function() {         session.setdefault('limit', 20)         var limit = session.get('limit') || 20         meteor.subscribe('goods', this.params.cat, limit)     } }) 

the idea user can press bunch of buttons change cat(egory), filtering out data remaining on same route. classic stuff.

right sets default limit of 20 , user scrolls down, increased. if clicks button change category, doesn't make sense instantly load 100 new items, set limit 20 again.

problem is, can't think of way that. removing setdefault use session.set won't work. can think of right logging cat in session , use check if category has been changed, hoping there better way.

how using template manage state (instead of sessions , route.

for example, using reactivate variable (reactive-var package), , passing category through route template. way - categories can linked (and limits expanded/limited needed).

start instantiating template

template.limiteddatasource.created = function() {   this.data.limitvar = new reactivevar(20);   this.data.dssub = meteor.subscribe('goods', this.data.category, this.data.limitvar.get()) } 

add template level helpers manage subscription readyness , data

template.limiteddatasource.helpers({     datasourceready: function() {         return this.dssub.ready();     },     datasource: function() {         return collectioname.find({cat: this.category}, {limit: this.limitvar.get()});     } }); 

add event handlers load in more things (maybe change limit?)

template.limiteddatasource.events({     'click .showmore': function(event, template) {         event.preventdefault();         var newlimit = template.data.limitvar.get() + 20;         template.data.limitvar.set(newlimit);     },  }); 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -