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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:17:27+00:00 2026-06-01T12:17:27+00:00

I send a model to a template. The model has a collection. In the

  • 0

I send a model to a template. The model has a collection. In the template I echo some variables and functions:

console.log(comments);
console.log(_.size(comments));
console.log(comments instanceof App.Collections.Comments);
console.log(_.pluck(comments, 'created'));
_.each(comments, function(com) {
    console.log(com);
});

The first three work, but the last two underscore functions don’t. Pluck gives 3x undefined and each doesn’t iterate.

Object { length=3, models=[3], _byId={...}, more...}
3
true
[undefined, undefined, undefined]

How do I get the underscore functions to work?

  • 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-01T12:17:29+00:00Added an answer on June 1, 2026 at 12:17 pm

    Backbone collections have some Underscore methods mixed in so you can use the Underscore methods directly on the collection instance:

    console.log(comments.pluck('created'));
    comments.each(function(com) { console.log(com) });
    

    Demo: http://jsfiddle.net/ambiguous/3jRNX/

    This one:

    console.log(_.size(comments));
    

    works fine for you because _.size looks like this:

    _.size = function(obj) {
      return _.toArray(obj).length;
    };
    

    and _.toArray calls the collection’s toArray:

    // Safely convert anything iterable into a real, live array.
    _.toArray = function(iterable) {
      if (!iterable)                return [];
      if (iterable.toArray)         return iterable.toArray();
      if (_.isArray(iterable))      return slice.call(iterable);
      if (_.isArguments(iterable))  return slice.call(iterable);
      return _.values(iterable);
    };
    

    which unwraps the collection’s data to give you the correct length. The above is taken from the 1.3.1 source, the current Github master version‘s _.size has a different implementation so your _.size call is likely to break during an upgrade.

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

Sidebar

Related Questions

I have an app called blog that has a model called Entry. I use
I want to send ViewData.model to Special action with the last user data entry.
I have ajax request that do 3 missions: Save Model (DB) Send Email Give
Question: How do send data to a view model when using command binding? So
How to call few model methods and send emails through my rake task?
If a model changes an attribute locally, then changes it back, ActiveRecord doesn't send
Requirment: To generate invoice in pdf format on company template and send it in
so, the create action on my model works, but it won't send a the
I am trying to send a model to ASP.NET MVC controller action, but for
I have a Rails app (2.3.8) where I send emails using ActionMailer from my

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.