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

  • Home
  • SEARCH
  • 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 9166239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:06:35+00:00 2026-06-17T15:06:35+00:00

I want to update KnockoutJS viewmodel from AJAX JSON entry. I am unsure how

  • 0

I want to update KnockoutJS viewmodel from AJAX JSON entry. I am unsure how to do this.

Here is my code:

 var CurrencyModel = function (Currencies) {
        var self = this;
        self.Currencies = ko.observableArray(Currencies);

        self.AddCurrency = function () {
            self.Currencies.push({
                CurrencyFrom: "",
                CurrencyTo: ""
            });
        };

        self.RemoveCurrency = function (Currency) {
            self.Currencies.remove(Currency);
        };

        self.Save = function (Form) {
            alert("Could Now Save: " + ko.utils.stringifyJson(self.Currencies));
        };

        $.ajax({
            url: "CurrencyConfiguration.aspx/GetConfiguredCurrencies",
            // Current Page, Method  
            data: '{}',
            // parameter map as JSON  
            type: "POST",
            // data has to be POSTed  
            contentType: "application/json; charset=utf-8",
            // posting JSON content      
            dataType: "JSON",
            // type of data is JSON (must be upper case!)  
            timeout: 10000,
            // AJAX timeout  
            success: function (Result) {
                //Need to Get method to Bind To CurrencyModel;
            },
            error: function (xhr, status) {
                alert(status + " - " + xhr.responseText);
            }
        });
    };

    $(document).ready(function () {
        var VM = new CurrencyModel();
        ko.applyBindings(VM);
    })

And here is the JSON Data that is obtained from the server:

{
"d": [
    {
        "__type": "Finance.Tracntrace.Members_Only.DAL.DataModel.Currency.CurrencyConfigurationDM",
        "CurrencyFrom": "ZAR",
        "CurrencyTo": "USD"
    },
    {
        "__type": "Finance.Tracntrace.Members_Only.DAL.DataModel.Currency.CurrencyConfigurationDM",
        "CurrencyFrom": "USD",
        "CurrencyTo": "ZAR"
    }
]
}

HTML:

  <table class="table table-striped">
            <thead>
                <tr>
                    <th>
                        Currency From
                    </th>
                    <th>
                        Currency To
                    </th>
                </tr>
            </thead>
            <tbody data-bind="foreach: Currencies">
                <tr>
                    <td data-bind="text: CurrencyFrom">
                    </td>
                     <td data-bind="text: CurrencyTo">
                    </td>
                </tr>
            </tbody>
        </table>

The Viewmodel Is extremely Simple, I have a currency From, and A currency to that I want to add and remove from a table.

  • 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-17T15:06:36+00:00Added an answer on June 17, 2026 at 3:06 pm

    I’d do two things here.

    First, define a class for Currency.

    var currency = function(data) {
      var self = this;
      self.CurrencyFrom = ko.observable(data.CurrencyFrom);
      self.CurrencyTo = ko.observable(data.CurrencyTo);
    }
    

    After that, your success method becomes something like this.

    success: function(Result) {
       // use jQuery's $.map function to translate values
       // should be stored in .d property, according to your JSON
       var mappedCurrencies = 
         $.map(Result.d, 
               // Here, $.map will just new up a new currency,
               // using the constructor argument to set fields
               function(item){ return new currency(item);});
    
       // Finally, set the currencies.  VM should update automatically.
       self.Currencies(mappedCurrencies);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a knockoutjs viewmodel defined like this: function TestViewModel() { var self =
I want to update the lastlogin column value .i wrote the code like this
What I want: Update all new commits from server with my local repository in
I want to update an erb.html page in rails with information from a webscraping
I am performing this request, and I get the results I want: UPDATE sales
I want update object with linq to entities, like this : public ActionResult SubmitPool(SwimmingPool
I want to create webservice which will do logical operations such read,write,insert,update records from
I want update position of Particles for store this information I use NSMutableArray. I
i want update textarea content onclock on a input button for example: <input type=button
i have ios application with xcdatamodeld, i want update some data so need a

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.