backbone.js removing template from DOM upon success

Posted by timpone on Stack Overflow See other posts from Stack Overflow or by timpone
Published on 2012-12-08T16:21:59Z Indexed on 2012/12/08 17:03 UTC
Read the original article Hit count: 295

Filed under:
|

I'm writing a simple message board app to learn backbone. It's going ok (a lot of the use of this isn't making sense) but am a little stuck in terms of how I would remove a form / html from the dom. I have included most of the code but you can see about 4 lines up from the bottom, the part that isn't working. How would I remove this from the DOM?

thx in advance

var MbForm=Backbone.View.extend({
  events: {
  'click button.add-new-post': 'savePost'
  },

  el: $('#detail'),
  template:_.template($('#post-add-edit-tmpl').html()),
  render: function(){
    var compiled_template = this.template();
    this.$el.html(compiled_template);
    return this;
  },
  savePost: function(e){
    //var self=this;
    //console.log("I want you to say Hello!");
    data={
     header: $('#post_header').val(),
     detail: $('#post_detail').val(),
     forum_id: $('#forum_id').val(),
     post_id: $('#post_id').val(),
     parent_id: $('#parent_id').val()
    };

    this.model.save(data, {
      success: function(){
        alert('this saved');
        //$(this.el).html('this is what i want');
        this.$el.remove();//  <- this is the part that isn't working


       /* none of these worked - error Uncaught TypeError: Cannot call method 'unbind' of undefined 
        this.$el.unbind();
        this.$el.empty();

        this.el.unbind();
        this.el.empty();
       */

        //this.unbind();
        //self.append('this is appended');
      }
    });

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about backbone.js