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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:39:36+00:00 2026-06-09T21:39:36+00:00

I want to sort my colection before I pass it to the template. I

  • 0

I want to sort my colection before I pass it to the template. I use in the render function of my view

CollectionForTelplate : this.Collection

I do the fetch as

var self = this;
//fetch done here
if (Collection.length > 0) {
    _.each(Collection, function(Model) {
        JSON.stringify(Model);
    }, this);
};
self.Collection = Collection;
self.render;
  1. Is there any other way by means of which I can pass the collection to the template?
  2. How do you sort a collection based on a string field of the model, say Model.name ? I tried writing a comparator in the collection and a sort function the view but unfortunately; it doesnot work for me
  • 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-09T21:39:38+00:00Added an answer on June 9, 2026 at 9:39 pm

    Is there any other way by means of which I can pass the collection to
    the template?

    Yes, collection’s have a toJSON() method so you can simply do something like

    render: function() {
      this._template({list: this.toJSON()}); //assuming your template is already compiled
      return this;
    }
    

    How do you sort a collection based on a string field of the model, say
    Model.name ? I tried writing a comparator in the collection and a sort
    function the view but unfortunately; it does not work for me

    You can simply define the comparator function on the collection, and it should keep itself sorted, here’s the example given in the docs

    chapters.comparator = function(chapter) {
      return chapter.get("page");
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to sort a list of integer values, but before sorting them I
I want to sort a collection by one of the properties which is a
this.col = Backbone.Collection.extend({ model: M, comparator: function(item) { return item.get(level); } }); This above
In C++, to sort a vector, a list or any collection, I would use:
Am trying to sort via a certain value in the function, Collection users =
You can pass a function pointer, function object (or boost lambda) to std::sort to
I want to sort a MongoDB collection based upon several fields, some ascending, other
i want to sort an ArrayList that has the type Node, like this :
I want to store buttons in some sort of collection, arraylist, so that I
I have many collections for many types I want to sort each collection by

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.