Skip to content

Instantly share code, notes, and snippets.

@chmac
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chmac/486b39e90376578fc112 to your computer and use it in GitHub Desktop.
Save chmac/486b39e90376578fc112 to your computer and use it in GitHub Desktop.
Filtered results in Meteor
# Server
Meteor.publish 'foo', (searchQuery) ->
return Foo.find
bar: searchQuery
# Client
Meteor.subscribe 'foo', Session.get 'searchQuery'
# {#each foo} in your template and then to update:
Session.set 'searchQuery', 'some new query'
Meteor.publish('foo', function(searchQuery) {
return Foo.find({
bar: searchQuery
});
});
Meteor.subscribe('foo', Session.get('searchQuery'));
Session.set('searchQuery', 'some new query');
@chmac
Copy link
Author

chmac commented May 5, 2014

This is obviously a simple example, but it shows the basic pattern of how to tie user input to a reactive data source and have the data filtered based on changing user input.

@chmac
Copy link
Author

chmac commented May 5, 2014

I added a javascript version for those who have difficulty reading the efficiency of coffeescript! ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment