我有一个模板,我代表一个有很多用户标签的用户。在我点击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();
}
}
});
谢谢!
答案 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);
});
}