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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:34:09+00:00 2026-06-13T18:34:09+00:00

The knockoutjs foreach alias does not work as explained in the knockoutjs docs halfway

  • 0

The knockoutjs foreach alias does not work as explained in the knockoutjs docs halfway down the page under:

Note 3: Using “as” to give an alias to “foreach” items

Here is a simple jsFiddle showing the error. The console says that the alias is not defined although I’ve followed the knockoutjs example…

HTML

<h3>This works</h3>
<ul data-bind="foreach: people">
    <li>
        <span data-bind="text: $data.name"></span> 
        <span data-bind="text: $data.age"></span>
    </li>
</ul>

<h3>This doesn't work</h3>
<ul data-bind="foreach: { data: people, as: 'person' }">
    <li>
        <span data-bind="text: person.name"></span> 
        <span data-bind="text: person.age"></span>
    </li>
</ul>​

JS

var data = [
    { name: 'Bob', age: 35 },
    { name: 'Sue', age: 24 },
    { name: 'Rick', age: 57 }
];

var model = function( data ){
    this.people = ko.observableArray( data );
}
ko.applyBindings( new model( data ) );​

Am I just not understanding the example and doing something wrong? It’s been known to happen, lol…

  • 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-13T18:34:10+00:00Added an answer on June 13, 2026 at 6:34 pm

    Upgrade to knockout 2.2.0 and it works. Upgraded fiddle here.

    Your bindings are fine – leave them as-is:

    <h3>This works</h3>
    <ul data-bind="foreach: people">
        <li>
            <span data-bind="text: $data.name"></span> 
            <span data-bind="text: $data.age"></span>
        </li>
    </ul>
    
    <h3>This doesn't work</h3>
    <ul data-bind="foreach: { data: people, as: 'person' }">
        <li>
            <span data-bind="text: person.name"></span> 
            <span data-bind="text: person.age"></span>
        </li>
    </ul>​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jQuery mobile and Knockout.js to test the first example on http://knockoutjs.com/documentation/foreach-binding.html
I'm binding data to a page using KnockoutJS, the ViewModel is being populated by
I am trying to update a KnockOutJS page using an Ajax call. The Update
I am using KnockoutJS on my page and trying to populate the DOM for
I'm using knockoutjs 2.0 I've been trying to have this table work in IE8
I have a bound list using knockoutjs / mvc3 <div data-bind=foreach: phones> <input data-bind='value:
I am using knockoutjs with the jquery drag & drop and it works well
I'm using KnockoutJS with ASP.NET MVC, and I'm having a problem with broken bindings
I am using KnockoutJS and I would like to know of a way where
I recently started working with KnockoutJs and quickly realized using the default Json(myModelWithADate) resulted

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.