Ember.js 向余烬数据模型添加数据时刷新余烬数据模型

Ember.js 向余烬数据模型添加数据时刷新余烬数据模型,ember.js,ember-data,Ember.js,Ember Data,我正在向包含Ember数据的Ember教程应用程序添加JSON API。应用程序的流程如下:加载网站:应用程序通过GET请求从API获取todo。添加todo:应用程序通过POST请求添加新todo编辑刚刚添加的todo:失败,因为尽管todo在数据库中,但应用程序不知道它,因为自从添加todo之后,它还没有得到todo列表。我想我需要的是每次添加新的todo时刷新todo列表。我尝试过这样做,但它只观察属性。只需使用实时记录数组即可 Takes a type and filter functi

我正在向包含Ember数据的Ember教程应用程序添加JSON API。应用程序的流程如下:
  • 加载网站:应用程序通过GET请求从API获取todo。
  • 添加todo:应用程序通过POST请求添加新todo
  • 编辑刚刚添加的todo:失败,因为尽管todo在数据库中,但应用程序不知道它,因为自从添加todo之后,它还没有得到todo列表。
我想我需要的是每次添加新的todo时刷新todo列表。我尝试过这样做,但它只观察属性。

只需使用实时记录数组即可

Takes a type and filter function, and returns a live RecordArray that
remains up to date as new records are loaded into the store or created
locally.

The callback function takes a materialized record, and returns true
if the record should be included in the filter and false if it should
not.

The filter function is called once on all records for the type when
it is created, and then once on each newly loaded or created record.

If any of a record's properties change, or if it changes state, the
filter function will be invoked again to determine whether it should
still be in the array.

例如:


试过了,还是没用。也许问题不仅仅是数据不同步。你如何添加一个新的记录,原始ajax调用?还是正在创建新记录?
createTodo:function(){var title=this.get('newTitle');if(!title.trim()){return;}var todo=this.store.createRecord('todo',{title:title,isCompleted:false});todo.save();}
我添加了一个示例,live record数组应该可以工作,我一直在使用它,你能给我看一下你的代码吗?谢谢你的例子,已经修好了!
this.store.all('post')

this.store.filter('post', function(post){ return post.get('body').indexOf('ember')>=0;});