是否可以将Ember中的商店绑定到模板中,以便当新对象被推送到商店时,模板会更新?
例如:
~route.js
App.PostsRoute = Em.Route.extend(
model: ->
this.store.findAll('post')
)
~template.hbs
{{#each post in controller}}
{{title} <br />
{{/each}}
~controller.js
App.SomeController = Em.Controller.extend(
actions:
add_new: ->
this.store.createRecord('post', {title: 'new post'})
)
我不希望从控制器更新模板明确性 我正在使用Ember 1.1.2 和Ember-Data 1.0.0.beta3
答案 0 :(得分:1)
从findAll切换到find,并使用all作为过滤器。
App.PostsRoute = Em.Route.extend(
model: ->
this.store.find('post') // find has to be called once for the all filter to work
return this.store.all('post')
)
顺便说一句,我不是coffeescript专家,所以这是对语法的猜测。
答案 1 :(得分:0)
我在读完这篇文章(http://emberjs.com/guides/models/frequently-asked-questions/)
后想出来了 带有查询的store.find在推送时不会更新 store.filter 会。
这篇文章解释得非常好。