From 70daa0f2512a2839b79bff7bff40a5e49da232fb Mon Sep 17 00:00:00 2001 From: Arvind Date: Wed, 5 Mar 2014 21:13:18 +0530 Subject: [PATCH] Code refactor. --- app.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 6945743..4bce8ee 100644 --- a/app.js +++ b/app.js @@ -11,9 +11,11 @@ }; var How = Backbone.Model.extend({ - defaults: { + defaults: function() { + return { 'comment':'', 'replyTo':'' + }; }, initialize: function() { } @@ -126,7 +128,9 @@ /* Create a sweet and send it to the sweet store. Update the view to include the comment */ e.preventDefault(); - this.model.set({'how': new How({'comment':this.$("textarea.form-control").val()})}); + + this.model.get('how').set({'comment':this.$("textarea.form-control").val()}); + console.log(this.model.get('how')); this.model.set({created: new Date().toUTCString().substr(0, 25)}); new LoginView({model:this.model}); @@ -178,7 +182,10 @@ }, showOne: function(model) { - model.set({'how': new How(model.get('how'))}); + if(model.get('how').isNew === undefined) { + console.log(model); + model.set({'how': new How(model.get('how'))}); + } var view = new CommentView({model:model}); $(this.el).append(view.render().el); } -- 1.7.10.4