Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8383319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:08:08+00:00 2026-06-09T17:08:08+00:00

I have a backbone project that pulls podcasts from verious API’s. The issue I

  • 0

I have a backbone project that pulls podcasts from verious API’s.

The issue I want to address is removing all the views currently displayed. I want to do this by binding an event to each view that fires when a “remove” anchor is clicked.

Currently the collection reset fires and removes all the models, but I have no way of making sure the views are destroyed as well. I think I need help with my logic.

Here is my code:

podSearch = Backbone.Model.extend();
podSearchCollection = Backbone.Collection.extend({
    model: podSearch,
    parse: function(response) {
        return response.results;
    }
});

ownerList = Backbone.Model.extend();
ownerListCollection = Backbone.Collection.extend({
    model: ownerList,
    parse: function(response) {
        return response.results;
    }
});

Search = Backbone.View.extend({
    initialize: function(){
        this.searchCollection = new podSearchCollection();
        this.searchCollection.bind('reset', this.appendResult, this);
    },
    events: {
        "click button" : "getTerm"
    },
    doSearch: function(term){
        /* get term and collection url */
        this.searchCollection.fetch();
    },
    appendResult: function(){
        _.each(this.searchCollection.models, function (item) {
            var listItem = new ownerItem({model:item});
            $('#results').append(listItem.render().el);
        });
    },
    removeAll: function(){
        console.log(this.searchCollection);
        this.searchCollection.reset();
    }
});

ownerItem = Backbone.View.extend({
    template: $("#castOwner").html(),

    initialize: function(){
        this.ownerListCollection = new ownerListCollection();
        this.ownerListCollection.bind('reset', this.appendResult, this);
        this.model.bind("reset", this.removeSelf);
    },
    render: function(){
        var tmpl = _.template(this.template);
        this.$el.html( tmpl( this.model.toJSON() ) );
        return this;
    },
    events: {
        "click a" : "pullCasts",
        "click a.removeAll" : "removeAll"
    },
    pullCasts: function(e){
        e.preventDefault();
        var id = this.$el.find('a').attr("href");
        this.ownerListCollection.url = 'http://itunes.apple.com/lookup?id=' + id + '&entity=podcast&callback=?';
        this.ownerListCollection.fetch();
    },
    appendResult: function(){
        _.each(this.ownerListCollection.models, function(item){
            /* do something with each item */
        }, this);
        $(this.el).append('<p><a href="#" class="removeAll">Remove All</a></p>');
    },
    removeAll: function(){
        search.removeAll();
    },
    removeSelf: function(){
        console.log("rm");
    }
});

search = new Search();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:08:09+00:00Added an answer on June 9, 2026 at 5:08 pm

    In order to remove the view when the model is destroyed, you can add a listener to your View, which will remove the view if the model gets destroyed :-

    initialize: function () {
        //view gets re-rendered if model is changed
        this.model.on("change", this.render, this);
        //view gets removed if model is destroyed
        this.model.on("destroy", this.remove, this)
    },
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Backbone.js collection that holds (for example) 30 items. I want to pass
i have a backbone.js api i want to use in an ExtJS app. Extjs
I have a rails-backbone project that generates jst.ejs templates. I'd like to include some
I have a project that involves three frontend developers. We're going to use backbone
Currently in a Backbone project I am working on, I have combined all templates
I have following piece of code from my Backbone project: App.Controllers.Test = Backbone.Router.extend({ routes:
I currently have two Backbone models: user and project. I would like to have
I'm working on a backbone.js project and I'm calling my github repo. I have
I have backbone view that binds an action to an element in the DOM.
I have a Backbone.js application that allows users to create graphs based on large

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.