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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:02:47+00:00 2026-06-15T05:02:47+00:00

I am uploading files asynchronously (using FormData) at specific index in the list of

  • 0

I am uploading files asynchronously (using FormData) at specific index in the list of files with:

files.create({position: index + 1 }, {at: index}); // files is Backbone.Collection

The server then saves upload and shifts positions for the files after specific position to free the place for the new inserted file.

Then on client I listen to add event and use index from options to insert file view.

files.on("add", function(model, collection, options) {
    // insert file view at options.index position
})

I also update position attribute for all models in collection:

files.on("add remove", function(){ 
  this.each(function(m, index) {
    m.set({position: index + 1});
  })
});

The problem is when I upload many files at one time at the same index position, file views append to the list in the wrong order.

How to ensure correct order and position attribute for file models in backbone collection?

  • 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-15T05:02:49+00:00Added an answer on June 15, 2026 at 5:02 am

    I was able to override collection.create that queues ajax requests. To do so I used the code from this answer.

    var Documents = Backbone.Collection.extend({
    
      model: Document,
    
      url: "/a/documents",
    
      initialize: function() {
        this.on("add remove", this.updatePositions, this);
        this.ajaxQueue = $({});
      },
    
      updatePositions: function(model, collection, options) {
        this.each(function(m, index) {
          m.set({position: index + 1});
        })
      },
    
      create: function(model, options) {
        var jqXHR
          , dfd = $.Deferred()
          , promise = dfd.promise()
          , coll = this;
    
        // queue our ajax request
        this.ajaxQueue.queue(doRequest);
    
        // add the abort method
        promise.abort = function(statusText) {
          // Proxy abort to the jqXHR if it is active
          if (jqXHR) {
            return jqXHR.abort(statusText);
          }
    
          // If there wasn't already a jqXHR we need to remove from queue
          var queue = this.ajaxQueue.queue()
            , index = $.inArray(doRequest, queue);
    
          if (index > -1) {
            queue.splice(index, 1);
          }
    
          // Reject the deferred
          dfd.rejectWith(options.context || options,
                         [promise, statusText, ""]);
    
          return promise;
        };
    
        // Run the actual collection.create
        function doRequest(next) {
          options = options ? _.clone(options) : {};
          model = coll._prepareModel(model, options);
          if (!model) return false;
          if (!options.wait) coll.add(model, options);
          var success = options.success;
          options.success = function(nextModel, resp, xhr) {
            if (options.wait) coll.add(nextModel, options);
            if (success) {
              success(nextModel, resp);
            } else {
              nextModel.trigger('sync', model, resp, options);
            }
          };
          jqXHR = model.save(null, options)
            .done(dfd.resolve)
            .fail(dfd.reject)
            .then(next, next);
        };
    
        return promise;
      }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've succeeded in uploading files to folders on my server using codeigniter along with
I'm using this code to upload files asynchronously to my web server. WebClient fileUploader
When uploading files to a web server using HTTP post, are there any restrictions
I'm uploading files (images) to my file structure using Uploadify, then catching each file,
I am uploading files(.cvs,.zip,.rar,.doc,.png,.jpg...) to ftp server. The strange is everything is successfully but
I have a java applet for uploading files to server. I want to display
Hi am using apache commons upload for uploading files File file=this.getFile();//getter method for the
I have a plugin for uploading files using jquery uploadify. After calling a method
What are best practices for uploading files using PHP to ensure that a database
I am uploading files from local to FTP using perl Net::FTP Module. After uploading

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.