I have a search
model in my app which loads dynamically when the users types something in the search box. The this.store.query('search', {query: "xyz"})
is called on keyUp()
and fetches the data from the API backend. However, looks like I'm missing something here because in Ember Inspector I don't see the data to be loaded for the search
model. Anyway, this is not my biggest concern because I don't know if ember inspector loads data from the store dynamically or only on refresh. My problem is that I can't access the data returned from the server in the template.
I have to mention that I don't have a route for search results, this is more like IMDb-like search box, where the results are loaded as search box kind of autocomplete instant results.
My code:
/templates/components/search-box.hbs
{{input value=query}}
<div>
// search results should be displayed here
</div>
/templates/components/app-bar.hbs
<nav>
{{#link-to 'index' tagName='button'}}Home{{/link-to}}
{{search-box value=query action="search"}}
</nav>
/templates/application.hbs
{{app-bar action="search"}}
{{outlet}}
/components/search-box.js
import Ember from 'ember';
export default Ember.TextField.extend({
keyUp: function(e){
if (this.get('value'))
this.sendAction('action', this.get('value'));
}
});
/components/app-bar.js
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
search: function(query){
this.sendAction('action', query);
}
}
});
/controllers/application.js
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
search: function(query){
this.store.query('search', {text: query});
}
}
});
Shouldn't this.store.query('search', {text: query});
automatically push records into the store? If it does, how can I access them inside my /templates/components/search-box.hbs
component?
Thank you!
Aucun commentaire:
Enregistrer un commentaire