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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:03:30+00:00 2026-05-25T20:03:30+00:00

My simple ‘dependent observable’ does not update and when I give it the syntax

  • 0

My simple ‘dependent observable’ does not update and when I give it the syntax of a function as the turorials say is required I get a javascript error. I’m just trying to sum the three observable values.

If I use

<td>${G1 + G2 + G3}</td>

I get a static display: the does not update when the other input fields change.

If I use the viewModel.Series I get no display of values at all.
If change viewModel.Series to: this.G1() + this.G2() I get a javascript error saying G1 is NOT a function.

var initialData = {"DateId":32,"Scores":[{"Alias":"Cap Stocks","G1":129,"G2":123,"G3":222,
var theScores = initialData.Scores;
var viewModel = {scores : ko.observableArray(theScores) };
viewModel.Series = ko.dependentObservable(function() {
    return this.G1 + this.G2 + this.G3;
 }, viewModel);
$(function () {
ko.applyBindings(viewModel); }

Here is my template binding that at least displays something

<td> ${Alias}</td>
<td><input data-bind="value: G1"/></td>
<td><input data-bind="value: G2"/></td>
<td><input data-bind="value: G3"/></td>
<td>${G1 + G2 + G3}</td> 
  • 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-25T20:03:31+00:00Added an answer on May 25, 2026 at 8:03 pm

    In this case you would need to make the G1, G2, and G3 properties observable. An observableArray notifies when there are changes to the array itself, but not individual properties on its items.

    You could use something like the mapping plugin or map it yourself using a constructor function that either takes in a score object or each property.

    function Score(alias, g1, g2, g3) {
       this.Alias = alias;
       this.G1 = ko.observable(g1);
       this.G2 = ko.observable(g2);
       this.G3 = ko.observable(g3);
    
       this.Series = ko.dependentObservable(function() {
           return parseInt(this.G1(), 10) + parseInt(this.G2(), 10) + parseInt(this.G3(), 10);
       }, this);
    }
    

    Then, map your existing array:

    var theScores = ko.utils.arrayMap(initialData.Scores, function(score) {
        return new Score(score.Alias, score.G1, score.G2, score.G3);    
    });
    

    Sample here: http://jsfiddle.net/rniemeyer/SbFDR/

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

Sidebar

Related Questions

simple question maybe but can't find solution. I have button for refresh/update some contents
Simple question, but couldn't find the answer. When the function 'enkelpost'is called anywhere in
Simple problem, though apparently not a simple solution. Example here: http://myhideout.eu/new/ Basically the site
Simple (I hope), HTML question. Let's say I have a column group that spans
Simple Wordpress problem - get_post_meta is not retrieving custom field values. Here's the code
Simple question.. just can't get the result set in the order I need :p
Simple question, not sure what the best answer is although I suspect it involves
Simple question, but could somehow not find any answer on google (maybe it's just
Simple Concept that is not working: I'm trying to connect to the web and
Simple question about the realloc function in C: If I use realloc to shrink

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.