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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:52:59+00:00 2026-06-04T00:52:59+00:00

I seem to have stumbled into an interesting anomoly with KnockoutJS. I have an

  • 0

I seem to have stumbled into an interesting anomoly with KnockoutJS.

I have an object with an ko.obseravableArray in it.

I can programmatically, before I apply bindings add items to the array. When the UI updates it looks correct. Then when I click on a button to add an item to the array it appears as if nothing has happened. However, when I remove an item from the array the UI then updates.

 var Feature = function (desription, price)
 {
    var self = this;

    var _description = desription;
    self.description = ko.observable(_description);

    var _price = price;
    self.price = ko.observable(_price);
}

var ItemFeature = function(feature) 
 {
    var self = this;

    var _feature = feature;
    self.feature = ko.observable(_feature);
}

var Item = function ()
{
    var self = this;

    self.featuresList = [
    new Feature("Feature 1", 1.50),
    new Feature("Feature 2", 2.00)
    ];

    self.features = ko.observableArray();

    self.addNewFeature = function () {
        self.features().push(new ItemFeature(self.featuresList[0]));
    }

    self.removeFeature = function (sender) {
        self.features.remove(sender);
    }
}

var _viewModel = new Item();
_viewModel.addNewFeature();
ko.applyBindings(_viewModel);

And the markup:

 <table>
            <thead><tr>
                <th>Feature</th>
                <th>Cost</th>
            </tr></thead>
            <tbody data-bind="foreach: features">
                <tr>
                    <td><select data-bind="options: $root.featuresList, value: feature, optionsText:'description'"></select></td>
                    <td data-bind="text: feature().description"></td>
                    <td data-bind="text: feature().price"></td>
                    <td><a href="#" data-bind="click: $root.removeFeature">Remove</a></td>
                </tr>
            </tbody>
        </table>

        <a href="#" data-bind="click: addNewFeature">Add a feature</a>

I have also put together an example of this.
http://jsfiddle.net/Q6J6a/7/

I feel like I’m missing something small, but it’s not jumping out at me.

  • 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-04T00:53:01+00:00Added an answer on June 4, 2026 at 12:53 am

    You want to do:

    self.features.push(new ItemFeature(self.featuresList[0]));
    

    rather than:

    self.features().push(new ItemFeature(self.featuresList[0]));
    

    So, you want to call push on the observableArray and not the underlying array, so that it notifies subscribers.

    http://jsfiddle.net/rniemeyer/Q6J6a/8/

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

Sidebar

Related Questions

I seem to have stumbled across a really weird issue when posting a static
I seem to have stumbled over a problem regarding saving an xml file from
Stumbled into another roadblock. Right now I have a page containing Plupload and a
I Have stumbled across CNN's website today http://edition.cnn.com/TECH/ they seem to have several other
I seem to stumble on problem after problem giving my entities behaviour. I have
I seem to have a problem passing some strings on from one form to
I seem to have found a bug in jQuery UI that duplicates dragged elements
I seem to have hit a snag while building my project using Ant. The
i seem to have some trouble installing autopy.h https://github.com/msanders/autopy/#introduction i already tried the installation
I seem to have the Twitter Bootstrap carousel working properly as far as moving

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.