我的应用程序中有一个search模型,当用户在搜索框中输入某些内容时,它会动态加载。this.store.query('search', {query: "xyz"})在keyUp()上被调用,并从keyUp()后端获取数据。但是,我在这里似乎遗漏了一些东西,因为在Ember检查器中,我没有看到要为search模型加载的数据。无论如何,这并不是我最关心的问题,因为我不知道成员检查器是动态地或仅在刷新时从存储加载数据。我的问题是无法访问模板中从服务器返回的数据。
我必须指出的是,我没有搜索结果的路径,这更像是IMDb样的搜索框,其中的结果作为搜索框加载,类似于自动完成即时结果。
我的代码:
/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});
}
}
});this.store.query('search', {text: query});不应该自动将记录推入商店吗?如果是这样,我如何在我的/templates/components/search-box.hbs组件中访问它们?
谢谢!
发布于 2015-11-26 10:55:43
路由中的模型钩子通常会设置您的模型,但是如果您从控制器加载记录,则需要自己进行此操作。
this.set('model', this.store.peekAll('search'));https://stackoverflow.com/questions/33936036
复制相似问题