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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:00:38+00:00 2026-05-31T07:00:38+00:00

I try to bind observableArray to div on my page and everything is ok.

  • 0

I try to bind observableArray to div on my page and everything is ok. This array contains simple JSON objects, not observable, obtained from WebService.

After that, I want to be able to modify those objects in array and would like view to be refreshed with each modification. For example, when checkbox gets clicked I would like to change the flag on my JSON object (this seems to work automatically all right) and at the same time my UI should get updated, which does not happen. Could anyone provide me with the reason (is this because those objects are simple, not observable?) and solution?

    var DocumentContentModel = function () {
        var self = this;
        self.content = ko.observableArray();
        self.ElementApprovalChanged = function (element) {
            DocumentService.DoSomething(
                element.Id,
                function (result) {
                    if (!result) {
                        var negatedApproved = !element.Approved;
                        element.Approved = negatedApproved;
                    }
                },
                function (error) {
                    alert(error);
                });
            return true;
        };
    };

    $(document).ready(function () {
        var contentModel = new ContentModel();
        DocumentService.GetContent(1,
        function (result) {
            contentModel.content(JSON.parse(result));
        });

        ko.applyBindings(contentModel);
    });

UI

<div class="ContentContainer">
    <div data-bind='foreach: content'>
        <div class="ContentElement" data-bind='css: { NotApproved: !Approved} '>
           <div class="ContentValue" data-bind='html: Value'></div>
            <div class="Approval">
                <input type="checkbox" data-bind='checked: Approved, click: $root.ElementApprovalChanged' />
            </div>
         </div>
     </div>
</div>

What is happening is on checkbox click I send request to webservice and if this call returns false I want to reset element’s Approved flag. And even whithout that, selecting checkbox should change div class attribute to mark it as NotApproved when needed. But none of this happens.

  • 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-31T07:00:40+00:00Added an answer on May 31, 2026 at 7:00 am

    An observableArray only tracks the array. So if something is added, removed or replaced in the array this will trigger an update to your view.

    An observableArray does NOT track the state of individual properties on the items in the array. So if you have an Approved flag on your objects this needs to be an observable for the UI to reflect changes to that property.

    So you would have something like:

    element.Approved = ko.observable(false);
    ....
    ....
    
    if (!result) {                         
      var negatedApproved = !element.Approved();                         
      element.Approved(negatedApproved);                     
    } 
    

    (or if you want to be more consise:

    element.Approved(!element.Approved()); 
    

    )

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

Sidebar

Related Questions

I try to bind value from input select to attribute selectedValue in controller. This
When I try to bind overloaded property in PDOStatement::bindParam method, $stmt->bindParam(':'.$field.'', $this->$field, $pdoparam); ...
I try to bind a NSString value into my SQL query but its not
Made a simple test project where i try to bind to a xmldatasource in
I try to bind an IPv6 server socket in Java 1.6 on Windows 7,
When I try to bind port 80 to a socket in c, i always
I am try to bind the dropdowmlist using jquery. But is showing some error.
I'm trying to bind a function with a non-existent class. I will try to
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
Try to see which cast is faster (not necessary better): new c++ case or

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.