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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:43:40+00:00 2026-06-15T08:43:40+00:00

I have an observable array containing objects (dynamically created) that have themselves observable attributes.

  • 0

I have an observable array containing objects (dynamically created) that have themselves observable attributes. So far so god, but when I try to add a computed observable to the dynamically created object, the observables of the object resolve to undefined.

// Object whose model has an observable array and an instance of the dynamically generated objects

function SecretSanta(params) {
    ... 
    ko.applyBindings(new this.Model(this));
};

SecretSanta.prototype = {
    ...
    Model: function(secretSanta) {

        var self = this;
        this.secretSanta = secretSanta;
        this.newSanta = new Santa();

        this.santas = ko.observableArray();

        this.addSanta = function() {
            self.santas.unshift(new Santa(self.newSanta.getName(), self.newSanta.getEmail()));
            self.newSanta.clear();
        }

        this.removeSanta = function(santa) {
            self.santas.splice(self.santas.indexOf(santa), 1);
        };

        this.santasCount = ko.computed(function() {
            return self.santas().length;
        });

        this.valid = ko.computed(function() {
            return self.santasCount() >= self.secretSanta.VALID_SANTAS;
        });
    }
};

// Dynamically generated objects
function Santa(name, email) {
    var self = this;

    this.name = ko.observable(name);
    this.email = ko.observable(email);

    this.valid = ko.computed(function () {      
        return self.name().match(/\w{3,}/);
    });     
}

In the last line of code the console is complaining that self.name() is undefined; if i get rid of the computed initialization and set this.valid to the function inside, it works fine (but the bindings do not get update).

Can any one point out what i am doing wrong?. Thanks a lot in advance.

I provide a link to the complete code http://jsfiddle.net/jeAtT/5/

  • 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-15T08:43:41+00:00Added an answer on June 15, 2026 at 8:43 am

    Computed observables are evaluated immediately when you create them. At the time of creation the value of self.name() is undefined. So, you are not able to call match off of undefined.

    One option would be to initialize your name like:

    this.name = ko.observable(name || "");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Knockout observable array that I wish to edit from within Javascript
I am new to Knockout.js, I have created an observable array and initialized with
I have an observable collection of objects that I'd like to display on the
I have an observable array that holds a list of people and a table
I have a Knockout.JS observable array that is the basis for a list: self.list_elements
I have a view model setup with an observable array of user objects. The
I have the following issue: I have an observable array of objects in the
i have a an observable array in my model that is bind to just
I have an observable array with var items= [ {image: /images/image1.jpg }, {image: /images/image2.jpg
I have a an array of observable collections and I want to display all

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.