I am new to the spine, so itβs possible that I violate the very essence of the spine in this. Suggestions are welcome:
I created a wall system. Thus, there is a form that can be used to post updates on the wall.
Each update may contain comments on them. I am showing 10 updates at a time. So there are 10 comments. So I have a view:
CommentForm=Backbone.View.extend({ initialize:function(messageView){ }, events:{ "submit":"postcomment" }, showMessage:function(data){ if(data.success) type="success"; else type="error"; message=data.error?data.error:"Update posted successfully"; $messageContainer=$this.prev(); console.log($this); var html="<div class='alert alert-"+type+"'>"+message+"</div>"; $($messageContainer).html(html); }, postcomment:function(){ $this=$(this.el); $.post(baseUrl+"/portal/post-comment",$this.serialize(),this.showMessage,"json"); return false; } });
Now I create an instance for it as follows:
commentFormView= new CommentForm({el:$(".comment-form form")});
Note that .comment-form is a div. There are several such elements. The event handler is attached to all comment forms just fine. But when I use $this=$(this.el); , he always refers to the first form of comment. How can i solve this. $ (this.el) should refer to the current instance of the comment form where the event was triggered, not the first
source share