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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:54:45+00:00 2026-06-07T15:54:45+00:00

I have created a View Model object for use with KnockoutJS. It has a

  • 0

I have created a View Model object for use with KnockoutJS.

It has a property called ‘Years’ which is an observable array…

viewModel.Years = ko.observableArray([]);

I then have a computed observable, in which I want to update the contents of the array…

viewModel.FuturePrediction = ko.computed(function () {
    viewModel.Years.removeAll();

    // etc...
});

The problem I’m having is that this appears to create an infinite loop. I’m guessing that Knockout is detecting that I’m accessing the ‘Years’ property and creating a dependency between it and the ‘FuturePrediction’ property.

As soon as I attempt to modify the contents of the array, the computed function gets triggered again. The problem is that all I’m doing is updating the ‘Years’ array, not reading it – and therefore there isn’t actually a dependency.

Any ideas what I can do to resolve this?

  • 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-07T15:54:47+00:00Added an answer on June 7, 2026 at 3:54 pm

    In KO 2.1, computed observables cannot trigger themselves, so you would be in better shape with 2.1.

    Calling the array manipulation methods do read and set the array, so it would create a dependency. You could do viewModel.Years([]); as long as you are not depending on the original underlying array for anything (have references to it elsewhere).

    I am not sure about your full scenario, but an option would be to build up your “new” array and then finally set the result as the value of Years rather than clearing it first.

    Like:

    viewModel.FuturePrediction = ko.computed(function () {
        var result = [];
        //add things to result
    
        viewModel.Years(result);
    });
    

    Again, I am not sure about your exact scenario, but if the end goal is to create a new array based on some criteria, then you could have FuturePrediction be the array and return it as the result of the computed observable. Just not sure about your situation exactly.

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

Sidebar

Related Questions

if i have created a view model and have a partial form that is
I have created model, controller and view with rails scaffold generator: rails g scaffold
I have a button created in my view. In the ViewModel, I wish to
I have created View A and View B. My window has View A displayed
I have created navigaton view using Sencha touch 2. Navigation view has list component
I have created a View which prompts the user to input some records with
I have created a view in which there is a capture button. When i
I'm using MVVM (MVVM Light Toolkit) and have a property on the view model
I have three models that are coming together to create one view model and
I have created a view for a table as: CREATE VIEW anonymous_table AS SELECT

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.