Last active
August 29, 2015 14:01
-
-
Save chmac/486b39e90376578fc112 to your computer and use it in GitHub Desktop.
Filtered results in Meteor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Meteor.publish('foo', function(searchQuery) { | |
return Foo.find({ | |
bar: searchQuery | |
}); | |
}); | |
Meteor.subscribe('foo', Session.get('searchQuery')); | |
Session.set('searchQuery', 'some new query'); |
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
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.