0

I have a template where I represent a User which hasMany usertags. The values are there after I hit F5, I'm not sure how to automatically refresh the view. I've looked into the ember observer, but it only fires after the DOM load - anyway I'm not sure if observers are the answer yet so looking for a fresh opinion on how to do this.

{{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();  
      }
   } 
});

Thanks!

MikeW
  • 4,749
  • 9
  • 42
  • 83

1 Answers1

0

Check out this answer.

After you save, you want to add your usertag to the user.usertags array.

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);
  });  
} 
Community
  • 1
  • 1
claptimes
  • 1,615
  • 15
  • 20