It seems when new controllers are created based on DiscussionController
prototype, its properties are shallow-copied. Since your newComment
is a reference type, you end up with 3 controllers all sharing a same instance. Only when you click 'Create' do individual controllers get their own instances.
One potential solution:
App.DiscussionController = Ember.Controller.extend({
isExpanded: false,
newComment: null,
actions: {
toggleExpand: function(){
this.toggleProperty('isExpanded');
if (!this.get("newComment")) {
this.set("newComment", {body:""});
}
},
createComment: function() {
this.set('newComment', {
body: ''
});
}
}
});