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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:11:04+00:00 2026-05-30T17:11:04+00:00

I have a knockoutjs viewmodel defined like this: function TestViewModel() { var self =

  • 0

I have a knockoutjs viewmodel defined like this:

    function TestViewModel() {
    var self = this;
    self.matches = ko.observableArray([]);
    self.selectedItem = ko.observable(self.matches()[0]);
    self.SelectMatch = function (match) {
        self.selectedItem(match);
    };
    self.setMatchList = function (_data) {
        self.matches(_data);
    };
}

I also have a function that gets called from a click event using straight javascript — no knockoutjs databinding involved. The script retreives a JSON array from the server like so:

        $.ajax({
        type: 'post',
        contentType: "application/json; charset=utf-8",
        url: "/FindMatches",
        timeout: 10000,
        data: JSON.stringify({ firstname: $("#Person_ProperFirstname").val(), lastname: $("#Person_ProperLastname").val(), gender: $("#Person_Gender").val().substring(0, 1) }),
        success: function (results) {
            if (results.length < 1) {
                //setErrorMessage("No matches were found.");
            }
            else {
                //setErrorMessage("");
                $.each(results, function (item) {
                    TestViewModel.matches.push(item);
                });
                $("#parent_dialog").dialog("open");
            }

Now I want to update the matches observableArray on my viewmodel with the results returned from the server but I’m having trouble figuring out how to do this. Besides what you see in the above script, I’ve also tried the following:

else {
   TestViewModel.matches(results);
}
//also this
else {
   TestViewModel.setMatchList(results); }

Any help would be greatly appreciated.

  • 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-30T17:11:06+00:00Added an answer on May 30, 2026 at 5:11 pm

    I’m assuming that your code initializes your ko bindings with a line similar to :

    ko.applyBindings(new TestViewModel(data.d));

    If you will create a variable of the instance of your model, you could reference it in other code.

    var _tvm = new TestViewModel(data.d);
    ko.applyBindings(_tvm);
    

    Then your ajax results would have something like this :

    else {
       _tvm.matches(results);
    }
    

    This might not be exactly right, but should get you close…

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

Sidebar

Related Questions

I have a Knockout view model defined like this: function viewModel () { var
Lets say I have a viewmodel like this var viewModel = { Dtos: [{
I have something like the following: var ChildViewModel = function (viewModel) { // state
I have a list of objects, each with a few fields, like this: function
Currently I have a simple knockoutJS object, with a few observables. But this object
I feel like this must have been asked before, but I've looked at Knockout
I have anchor tag like this <a href=# class=btn btn-success order-btn data-bind=attr:{'data-tiername':$data.tierName, 'data-identifier' :
Is there a way to map from/to a POCO and knockoutjs observable? I have
Let's say I have a template like this <script id=rowTemplate type=text/x-jquery-tmpl> <tr> <a href=${
I'm using knockoutjs 2.0 I've been trying to have this table work in IE8

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.