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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:12:13+00:00 2026-05-31T01:12:13+00:00

having an observable array like so: this.list = ko.observableArray([ new GoalItem(1, ‘page’, ‘Getting started’,

  • 0

having an observable array like so:

            this.list = ko.observableArray([
            new GoalItem(1, 'page', 'Getting started', 0, '', [
                new GoalItem(2, 'page', 'Getting started 1.1', 0, ''),
                new GoalItem(3, 'video', 'Video', 0, '', [
                    new GoalItem(4, 'data', 'Data', 0, ''),
                    new GoalItem(5, 'test', 'Test', 0, '', [
                        new GoalItem(6, 'page', 'Test prep', 0, '', [
                            new GoalItem(7, 'video', 'Test video', 0, ''),
                            new GoalItem(8, 'file', 'Test file', 0, '')
                        ])
                    ]),
                    new GoalItem(9, 'page', 'Sample page', 0, '')
                ])
            ]),
            new GoalItem(10, 'page', 'More data tracking', 0, '', [
                new GoalItem(11, 'data', 'Data 1', 0, ''),
                new GoalItem(12, 'data', 'Data 2', 0, '')
            ])
        ]);

and let’s say the currently active item is

new GoalItem(4, 'data', 'Data', 0, '')

how can/would i “walk”

this.list

to get either the “next” item which should be

new GoalItem(5, 'test', 'Test', 0, '', [
                        new GoalItem(6, 'page', 'Test prep', 0, '', [
                            new GoalItem(7, 'video', 'Test video', 0, ''),
                            new GoalItem(8, 'file', 'Test file', 0, '')
                        ])
                    ]),

or get the “previous” item which should be

new GoalItem(3, 'video', 'Video', 0, '', [
                    new GoalItem(4, 'data', 'Data', 0, ''),
                    new GoalItem(5, 'test', 'Test', 0, '', [
                        new GoalItem(6, 'page', 'Test prep', 0, '', [
                            new GoalItem(7, 'video', 'Test video', 0, ''),
                            new GoalItem(8, 'file', 'Test file', 0, '')
                        ])
                    ]),
                    new GoalItem(9, 'page', 'Sample page', 0, '')
                ])

ideally with functions like

this.list.next()

and

this.list.previous()

hope this makes sense.

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-31T01:12:15+00:00Added an answer on May 31, 2026 at 1:12 am

    There are several ways that you could approach this one.

    I think that a simple way to handle it is to create a computed observable that represents a flattened version of your structure. This way it will always be correct as your various arrays change.

    Here is a sample of an approach to recursively add child items to a computed observable

    //to be called recursively
    var addChildren = function(array, result) {
        array = ko.utils.unwrapObservable(array);
        if (array) {
            for (var i = 0, j = array.length; i < j; i++) {
                result.push(array[i]);
                addChildren(array[i].children, result);
            }        
        }
    };
    
    //a flattened versions of the items
    this.flatItems = ko.computed(function() {
        var result = [];
        addChildren(self.items(), result);
        return result;
    });
    

    Here is a sample that shows moving next/previous through the flatItems: http://jsfiddle.net/rniemeyer/VHEYK/

    You could do this on-the-fly as well, just need to either do more looping to find each item’s location or attach meta-data so you now how to get back to the parent from an item.

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

Sidebar

Related Questions

I'm currently having problems having the UI refresh when I'm getting new data from
I am having some problems getting KnockoutJs beforeRemove and afterAdd handlers to fire. This
I'm new to Silverlight 4 and having a tough time googling this one since
Having a heckuva time with this one, though I feel I'm missing something obvious.
Having to upgrade a database schema makes installing a new release of software a
Having a problem getting a TreeView control to display node images. The code below
Having programmed through emacs and vi for years and years at this point, I
Having this route: map.foo 'foo/*path', :controller => 'foo', :action => 'index' I have the
Having difficulty articulating this correlated subquery. I have two tables fictitious tables, foo and
I am having a Observable Collection which contains my data values. I want to

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.