Last active
March 15, 2016 14:56
-
-
Save willmanduffy/a250757335efad84e62d to your computer and use it in GitHub Desktop.
Ember Search
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
| // app/controllers/resource/index.js | |
| import Ember from 'ember'; | |
| // The resource in the file path here is just whatever you are searching. In this app, it's emoji | |
| // but I wanted to standardize a bit. Here we are just defining the search query as a query param on | |
| // line 9 and then, when the search action is triggered by the form we set the query param on the | |
| // current route. | |
| export default Ember.Controller.extend({ | |
| queryParams: ['query'], | |
| actions: { | |
| search: function() { | |
| this.transitionToRoute({ | |
| queryParams: { | |
| query: this.get('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
| // app/routes/resource/index.js | |
| import Ember from 'ember'; | |
| export default Ember.Route.extend({ | |
| queryParams: { | |
| query: { | |
| refreshModel: true // This line is important so that when the query param is changed we call the server to get new data | |
| } | |
| }, | |
| model: function() { | |
| var params = this.paramsFor('resources.index'); | |
| return this.store.query('resource', { | |
| query: params.query | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment