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

  • Home
  • SEARCH
  • 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 6549229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:04:04+00:00 2026-05-25T12:04:04+00:00

So I already got this working using a loop but is wondering is there

  • 0

So I already got this working using a loop but is wondering is there is a cleaner way to do this.

Basically i got a model that got an array of ids from another model, currently I loop every id and add manually model to a new collection using this filter on the model collection.

getOneById : function(id){
    return this.filter(function(data) {
        return data.get("id") == id;
    });
},

Is there a way to directly return a list doing something like

getAllById : function(arrayIds){
    return _(this.filter(function(data) {
        ??????? return data.get("id") == eachID;
    }));
},

Thanks!

  • 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-05-25T12:04:05+00:00Added an answer on May 25, 2026 at 12:04 pm

    you could reduce the looping by checking to see if the id of your object is at an index > -1 in the array:

    function(arrayIds){
      var models = _.select(collection, function(model){
        return (_.indexOf(arrayIds, model.id) > -1);
      });
      return models;
    }
    

    this requires the inclusion of underscore.js in your code, but since you’re already using backbone, you already have that.

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

Sidebar

Related Questions

So I've already got this working but I'm hoping someone can help me optimize
I've already got a NAnt build script that builds/runs tests/zips web project together, etc.
I've already got my custom header drawing in my GridView using SetRenderMethodDelegate on the
I've got a conditional compilation symbol I'm using called RELEASE, that I indicated in
I've got a database that is mirrored using SQL 2008 Mirroring. I have a
I've got a loop which goes through various products being imported. Within this loop
I'm working in a web application using VB.NET. There is also VisualBasic code mixed
I'm working with dates since epoch, and already got, for example: date = 6928727.56235
I've got an issue involving a website that I have been using VS 2008
I really like Spark, but we've already got a big investment in webforms based

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.