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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:40:23+00:00 2026-06-02T23:40:23+00:00

I have a feeling I’m missing something simple here, but just can’t quite grok

  • 0

I have a feeling I’m missing something simple here, but just can’t quite grok this. Here is my script:

function FormDefinition()
{
    var self = this;
    self.Fields = ko.observableArray([new FieldDefinition()]);    
}

function FieldDefinition()
{
    var self = this;
    self.Name = "Test";
}
function ViewModel()
{
    var self = this;
    self.formDef = ko.observable(new FormDefinition());
    self.Name = "bob"
    self.addField = function(){
        this.formDef().Fields().push(new FieldDefinition());                    
    }            
}

ko.applyBindings(new ViewModel());

and here is my markup:

<a data-bind="click: addField">Add</a><br/>
<span data-bind="text: Name"></span>
<ul data-bind="foreach: formDef().Fields">
    <li data-bind="text: Name"></li>
</ul>​

and here is a jsFiddle: http://jsfiddle.net/5xSmr/

Expected behavior is that clicking ‘Add’ would cause the ui to update. debugging reveals that addfield is getting called.

  • 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-02T23:40:25+00:00Added an answer on June 2, 2026 at 11:40 pm

    Fixed your fiddle: http://jsfiddle.net/5xSmr/2/

    <a data-bind="click: AddField">Add</a><br/>
    <span data-bind="text: Name"></span>
    <ul data-bind="foreach: formDef().Fields()">
        <li data-bind="text: Name"></li>
    </ul>
    
    function FormDefinition()
    {
        var self = this;
        self.Fields = ko.observableArray();    
    }
    
    function FieldDefinition()
    {
        var self = this;
        self.Name = "Test";
    }
    function ViewModel()
    {
        var self = this;
        self.formDef = ko.observable(new FormDefinition());
        self.Name = "bob"
        self.AddField = function(){
            this.formDef().Fields.push({Name:"test"});
        }            
    }
    
    ko.applyBindings(new ViewModel());
    

    The main problem was that you were calling Fields() and not just Fields. Fields() return the unwrapped array and by pushing directly to it, ko would never know about it.

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

Sidebar

Related Questions

I have a feeling I'm missing something pretty simple here but, in this one
I have a feeling that I'm missing something simple here but can't seem to
I have a feeling that this question is very simple, but I just can't
I have a feeling this is something very obvious that I'm missing, but here
I have a feeling I'm doing something wrong here, but I'm not quite sure
I have a feeling I'm missing something very simple here. I have a class
I have a feeling that I'm missing something obvious but can't seem to resolve
I have a feeling this is a stupid question but I can't find the
I have a feeling that the answer to this is easy but I can't
I have a feeling this is something to do with the answer, but I'm

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.