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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:48:56+00:00 2026-06-07T13:48:56+00:00

I am using Backbone.Marionette’s CompositeView and I want to insert a new model at

  • 0

I am using Backbone.Marionette’s CompositeView and I want to insert a new model at index 0 of the collection and have it appear as the first view in the composite.

I have this code to insert the element:

PlansApp.Plans.collection.unshift new PlansApp.Plan data

The problem is that the CompositeView ignores the index of the newly inserted item in the collection.

in Backbone.Marionette, the appendHtml method looks like this:

  appendHtml: function(collectionView, itemView, index){
    collectionView.$el.append(itemView.el);
  },

The index argument is never used.

The newly inserted view will always be placed at the end of the composite.

How can I get it to appear at position 0?

  • 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-07T13:48:59+00:00Added an answer on June 7, 2026 at 1:48 pm

    This is by design, due to the number of edge cases that have been identified in supporting sorted collections directly.

    The index parameter was added so that developers could individually add support in their applications. There’s a wiki page that shows an example of how to do this: https://github.com/derickbailey/backbone.marionette/wiki/Adding-support-for-sorted-collections

    
    MySortedView = Backbone.Marionette.CompositeView.extend({
      // ...,
    
      appendHtml: function(collectionView, itemView, index){
        var childrenContainer = $(collectionView.childrenContainer || collectionView.el);
        var children = childrenContainer.children();
        if (children.size() === index) {
          childrenContainer.append(itemView.el);
        } else {
          childrenContainer.children().eq(index).before(itemView.el);
        }
      }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have very simple backbone model and collection. I have a corresponding backbone.marionette.CollectionView and
I'm using Backbone.js have a segmented control-type UI element for each model's view. They
I'm using Backbone.Marionette and need to render a view of employees and their respective
I am using backbone.js here is my scenario Lets say I have a view
Using Backbone I can fetch the Collection like below and render a Backbone View
I'm using backbone.js For example, let's suppose we have a products model and a
I've just started using Backbone.js. I want to create a Collection and add some
I have built a web app using backbone.marionette . When, from a Marionette.ItemView ,
Using Backbone and Marionette, I've created a new layout that goes into the main
I am using backbone.js. The elements in my collection are just in the order

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.