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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:26:34+00:00 2026-06-11T21:26:34+00:00

I understand each and collection helper methods are two possible ways to iterate over

  • 0

I understand each and collection helper methods are two possible ways to iterate over a list of items in my handlebars templates. I am looking for some practical advice about when to use each or collection and what are the differences between the two methods.

  • 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-11T21:26:35+00:00Added an answer on June 11, 2026 at 9:26 pm

    Each:

    App.myArray = [1,2,3]
    
    {{#each value in App.myArray}}
      <p>{{value}}</p>
    {{/each}}
    

    corresponding HTML

    <p>1</p>
    <p>2</p>
    <p>3</p>
    

    Collection:

    {{#collection contentBinding="App.myArray"}}
      <p>{{view.content}}</p>
    {{/collection}}
    

    corresponding HTML

    <div class="ember-view">
      <p>1</p>
    </div>
    <div class="ember-view">
      <p>2</p>
    </div>
    <div class="ember-view">
      <p>3</p>
    </div>
    

    As you can see both deal with arrays. In a nutshell each is used to display an array of elements while collection is used to display an array of views

    The main difference comes in practical use is when you want to interact with elements. If you just want to display a list of array use each helper.

    But if you want to interact with each of the element in the array while maintaining context of the clicked element you collections

    Let me explain with an example

    App.CollectionView = Ember.CollectionView.extend({
      //Here the content belongs to collection view
      content: [1,2,3],
      itemViewClass: Ember.View.extend({
        /*This itemViewClass is like a template which is used by 
        all the elements in the content array of collection view*/
        click: function(){
          //Now this itemViewClass has a content property which is the single element in the collections content
          /* As you see the content of collection view has 3 elements => 3 templates 
             1 single template = Ember.View.extend with it's own content property
             first template has content set to 1
             second template has content set to 2 and so on...
          */
          alert("you clicked"+this.get('content');
        }
      })
    })
    

    I think this clears your doubt…

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

Sidebar

Related Questions

Just to understand the collection ,I tried to find the square of each number
I understand that trusted silverlight applications can communicate with each other over the LAN
From what I understand IMAP requires a connection per each user. I'm writing an
I'm reading the JSlint Options Documentation to understand each of the available options, and
I found example of history.pushState() through stackoverflow but I don't understand what each thing
I understand that applications under the same domain name can talk to each other
I really can't understand how the below piece of code is working... options.each {
Can't understand the meaning of this phrase. People on forums suggests each other to
Each technology is powerful with libraries and frameworks, written for it. I understand, that
I've seen both used but I can't seem to understand when to use each?

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.