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 8105367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:08:37+00:00 2026-06-06T00:08:37+00:00

I have a standard list view setup with backbone that looks something like below.

  • 0

I have a standard list view setup with backbone that looks something like below. I have an instance where I need to remove an item, which is done in a remove function that destroys the model and unrenders the element. However just before the destroy/unrender I would like to select the previous element in the list.

Is there a good way to do this in backbone, right now the only thing I can think of is to do it with some jQuery, but I would like to know if there is a way to do go prev/next within backbone internally. Or would I need to set that up manually when appending my list items?

App = (function(Backbone, _){
    var Item = Backbone.Model.extend(
    {
        defaults:
        {
            part1: 'hello',
            part2: 'world'
        }
    });

    var ItemList = Backbone.Collection.extend({
        model: Item
    });

    var ListRow = Backbone.View.extend(
    {
        tagName: 'li',

        initialize: function()
        {
            _.bindAll(this, 'render');
        },

        render: function()
        {
            $(this.el).html('<span>'+this.model.get('part1')+' '+this.model.get('part2')+'</span>');

            return this;
        },

        remove: function()
        {
            //toggle previous element if exists before destory

            $this.model.destroy();
        },

        toggle: function()
        {
            this.$el.addClass('active');            
        }
    });

    var ListView = Backbone.View.extend(
    {
        el: $('#layout_content'),

        events:
        {
            'click button#add': 'addItem'
        },

        initialize: function()
        {
            _.bindAll(this, 'render', 'addItem', 'appendItem');

            this.collection = new TableList();
            this.collection.bind('add', this.appendItem);

            this.counter = 0;
            this.render();
        },

        render: function()
        {
            var self = this;
            $(this.el).append("<button id='add'>Add list item</button>");

            $(this.el).append("<ul></ul>");

            _(this.collection.models).each(function(item){ // in case collection is not empty
                self.appendItem(item);
            }, this);
        },

        addItem: function()
        {
            this.counter++;

            var item = new Item();

            item.set({part2: item.get('part2') + this.counter});

            this.collection.add(item);
        },

        appendItem: function(item)
        {
            var listRow = new ListRow({
                model: item
            });

            $('ul', this.el).append(listRow.render().el);
        }
    });

    var app = function(initialModels)
    {
        this.start = function()
        {
            this.listView = new ListView({collection: new ItemList(initialModels)});
        };
    };

    return app;
})(Backbone, _);


var app = new App([{"id":"95","note_title":"can we find the title"},{"id":"93","note_title":"some title"}]);
app.start();

​

  • 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-06T00:08:40+00:00Added an answer on June 6, 2026 at 12:08 am

    There seems to be no direct way inside backbone to accomplish this. I think that best that you can do, in the way of implementing this in Backbone, is to give each listrowview an index number when you add them to the listview and store the instances in an array within the listview. When destroying just go newindex = indexnumber +/- 1 and then show the view residing in the new index.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a SharePoint solution that uses a standard task list. We would like
I have a standard accordion that looks like <h3><a href=#>Section 1</a></h3> <div> <p> Mauris
I have a backbone viev which generates a list item view. In the render
If you have a standard ordered list in HTML like: <ol> <li>First</li> <li>Second</li> <ol>
I have configured the standard frontpage view in order to display a list of
I have an activity that has two tabs and a list view in each.
I have a UITableView that represents a list of objects, I'd like the user
I have a list of pictures being pulled from the standard flickr API, and
I have a standard active record model with an attributes that is required: class
I have an ImageView object that I'm setting the android:src=@drawable/some_xml_file instead of a standard

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.