如何刷新Ember视图

时间:2014-04-24 11:08:00

标签: ember.js

我有一个模板,我代表一个有很多用户标签的用户。在我点击F5之后,值就在那里,我不知道如何自动刷新视图。我已经调查了余烬观察者,但它只是在DOM加载后才开始 - 无论如何我不确定观察者是否还是答案,所以寻找关于如何做到这一点的新观点。

{{username}}
<span {{action 'addusertag' selectedTag}}>Add</span>
{{#each tag in model.usertags}}
{{/each}}


App.UserRoute = Ember.Route.extend({
   setupController: function(controller, model) {
      this.controller.set('model', this.get('store').find('user',model.id));
   },
   actions: {
      addusertag: function(params){
        var tag = this.get('store').createRecord('usertag', {tag_id: params.id, user_id: this.currentModel.id});                                                                                  
        tag.save();  
      }
   } 
});

谢谢!

1 个答案:

答案 0 :(得分:0)

查看此answer

保存后,您希望将usertag添加到user.usertags数组中。

addusertag: function(params){
  var context = this;
  var tag = this.get('store').createRecord('usertag', {tag_id: params.id, user_id: this.currentModel.id});                                                                                  
  tag.save().then(function (tag) {
     context.controller.get('content.usertags').pushObject(tag);
  });  
}