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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:24:08+00:00 2026-05-31T09:24:08+00:00

It’s probably best to explain with an example. This is an example linked from

  • 0

It’s probably best to explain with an example. This is an example linked from the Knockout blog on how to use $parent. However, in this case, $parent is apparently the same as $root, so I’m having trouble seeing the benefit.

Where it says $parent.lastUpdated, I’d like to instead access the observable array, this.products. I realize I could say $root.products. However, I’d like to generalize this, rather than write it explicitly for every list.

I will actually be using this in conjunction with ko.contextFor.

  • 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-31T09:24:09+00:00Added an answer on May 31, 2026 at 9:24 am

    You can’t get access (generically) to the observableArray that is being looped over directly inside of the foreach loop.

    $root and $parent is about the scope, so it will just give you the object that contains the observableArray.

    However, you can take advantage of this by ensuring that the scope is your observableArray by using the with binding.

    If you just need the underlying array, then you can do:

    <div data-bind="with: products">
        <ul data-bind="foreach: $data">
            <li>
                <strong data-bind="text: name"></strong>
                &mdash;
                Array length: <em data-bind="text: $parent.length"></em>
            </li>
        </ul>
    </div>​
    

    If you really need the observableArray, then you need to make sure that it has not been unwrapped (in the above example $data is unwrapped already). To do this, you can normalize the name of the array and look for it in your template like:

    <div data-bind="with: { theArray: products }">
        <ul data-bind="foreach: theArray">
            <li>
                <strong data-bind="text: name"></strong>
                &mdash;
                Array length: <em data-bind="text: $parent.theArray().length"></em>
            </li>
        </ul>
    </div>​
    

    Here is a sample: http://jsfiddle.net/rniemeyer/T6JvV/

    If you can’t live with the extra div, then you can certainly use the containerless control-flow bindings like:

    <!-- ko with: { theArray: products } -->
        <ul data-bind="foreach: theArray">
            <li>
                <strong data-bind="text: name"></strong>
                &mdash;
                Array length: <em data-bind="text: $parent.theArray().length"></em>
            </li>
        </ul>
    <!-- /ko -->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from

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.