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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:31:55+00:00 2026-06-06T10:31:55+00:00

Hello I have the following code which uses knockout.js, var allJobberDetailsArray = []; getAllJobberDetailsArray();

  • 0

Hello I have the following code which uses knockout.js,

var allJobberDetailsArray = [];
getAllJobberDetailsArray();
function getAllJobberDetailsArray() {
    $(function() {
        $.ajax({
            url: 'http://example.com',
            type: 'GET',
            data: {
                request: "yes",
                getAllJobberDetailsArray: "yes"
            },
            success: function(data) {
                allJobberDetailsArray = data;
            }
        });
    })
}

// ViewModel
function JobberCheckBoxListUserControlViewModel() {
    var self = this;
    self.allJobberDetailsArray = ko.observableArray(allJobberDetailsArray);
}
ko.applyBindings(new JobberCheckBoxListUserControlViewModel());

any change to allJobberDetailsArray I would like to update the UI automatically say an array item is added updated or deleted i would like the UI to reflect it.

How do i achieve it?

EDIT

var allJobberDetailsArray = ko.observableArray();

getAllJobberDetailsArray();

function getAllJobberDetailsArray() {
    $(function() {
        $.ajax({
            url: 'http://example.com',
            type: 'GET',
            data: {
                request: "yes",
                getAllJobberDetailsArray: "yes"
            },
            success: function(data) {
                allJobberDetailsArray.removeAll();
                allJobberDetailsArray.push(data);
            },
        });
    })
}

// ViewModel
function JobberCheckBoxListUserControlViewModel() {
    var self = this;
    self.allJobberDetailsArray = allJobberDetailsArray;// allJobberDetailsArray is now observable but any change to this doesn't reflect in the UI
}
var viewModel = new JobberCheckBoxListUserControlViewModel();
ko.applyBindings(viewModel);

in the above code i made the array itself observable and trying to auto update the UI if there are any changes to the array how do i achieve it?

  • 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-06T10:31:56+00:00Added an answer on June 6, 2026 at 10:31 am

    Firstly the array you are updating isn’t an observable array. Secondly your success callback actually overwrites the array. Finally you do not keep a reference to your viewModel so you are unable to properly update the observable array. ObservableArray wrap real arrays to make them observable. All add’s removes etc need to go through the observableArray so the subscribers can be notified.

    Try this instead.

    // ViewModel
    function JobberCheckBoxListUserControlViewModel(initialArray) {
        var self = this;
        self.allJobberDetailsArray = ko.observableArray(initialArray || []);
    }
    
    var viewModel = new JobberCheckBoxListUserControlViewModel();
    
    function getAllJobberDetailsArray() {
        $(function() {
            $.ajax({
                url: 'http://example.com',
                type: 'GET',
                data: {
                    request: "yes",
                    getAllJobberDetailsArray: "yes"
                },
                success: function(data) {
                    viewModel.allJobberDetailsArray(data);
                }
            });
        })
    }
    
    ko.applyBindings(viewModel);
    

    I would also recommend refactoring to put the getAllJobberDetailsArray method inside your viewModel so it doesn’t polute the global namespace and maintains encapsulation.

    Hope this helps.

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

Sidebar

Related Questions

I have a following code which works fine MsgBox(AddSomething(Of String)(Hello, World)) Public Function AddSomething(Of
Hello I have the following code, which I compile with gcc (>4.2) with -fopenmp
I have the following code, which works fine: <input type=button name=btnHello value=Hello onclick=Test();/> and
I have the following code: $('.getcode').click(function () { $('textarea').val(); var str = []; $('#group-wrap
Hello I have the following bit of code which seems to work, but I'm
I have the following block of code, which uses the JSCH library found at
I have an exe file which has the following code: while(1) printf("hello\n"); I'm executing
Hello I have the following code namespace ConsoleApplication2 { class Program { static void
I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int
I have the following code <a href=#inline class=fancy id=item1>hello item1</a> <a href=#inline class=fancy id=item2>hello

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.