javascript - After sorting initially with time and listing_url, why cant I do the same again? -
below code sorts field time
, listing_url
problem once sorting time
, unable sort listing_url
.
also once if sort listing_url
, cant sort again. feel there problem sessions got no idea do.
can add session delete o unset function code ?
tia
template.listitem.helpers({ entry :function() { var selector={}; var options={ sort:{} }; var sort_by_time = session.get('sort_by_time'); var sort_by_listing = session.get('sort_by_listing'); console.log('sort_by_time:', sort_by_time); console.log('sort_by_listing:',sort_by_listing); session.unset('sort_by_listing'); if (sort_by_time) { options.sort[sort_by_time] = -1; }; session.unset('sort_by_time'); if (sort_by_listing) { options.sort[sort_by_listing] = 1; }; console.log('selector:',selector); console.log('options',options); var facebookposts=facebookpost.find(selector,options); return facebookposts; session } })
@mark leiber figured out! works charm
template.listitem.helpers({
entry :function() {
var selector={}; var options={ sort:{} }; var sort = session.get('sort'); if(sort) { if(sort == 'created_at') options.sort[sort] = -1; if(sort == 'listing_url') options.sort[sort] = 1; } console.log('selector:',selector); console.log('options',options); var facebookposts=facebookpost.find(selector,options); return facebookposts;
} })
Comments
Post a Comment