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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:34:40+00:00 2026-06-17T09:34:40+00:00

I have an existing view model that lists currency codes that I want the

  • 0

I have an existing view model that lists currency codes that I want the conversion rates for. I utilize the Yahoo Finance API to get a JSON result for my Currencies.

How do I bind this 3rd Party JSON result to my existing ViewModel.

JSON from Yahoo Finance API:

parseExchangeRate({"query":{"count":1,"created":"2013-01-17T07:37:18Z","lang":"en-US","results":{"row":{"rate":"8.7967","name":"USD to ZAR"}}}});

My Viewmodel Code:

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

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

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

        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) {
                var MappedCurrencies =
              $.map(Result.d,
       function (item) { return new currency(item); });
                self.Currencies(MappedCurrencies);
            },
            error: function (xhr, status) {
                alert(status + " - " + xhr.responseText);
            }
        });
    };

    //3rd Party JSON result
    function getRate(from, to) {
        var script = document.createElement('script');
        script.setAttribute('src', "http://query.yahooapis.com/v1/public/yql?q=select%20rate%2Cname%20from%20csv%20where%20url%3D'http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes%3Fs%3D" + from + to + "%253DX%26f%3Dl1n'%20and%20columns%3D'rate%2Cname'&format=json&callback=parseExchangeRate");
        document.body.appendChild(script);
    }

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

My HTML:

        <table class="table table-striped">
            <thead>
                <tr>
                    <th>
                        Date Updated
                    </th>
                    <th>
                        Currency From
                    </th>
                    <th>
                        Currency To
                    </th>
                    <th>
                        Conversion Rate
                    </th>
                    <th />
                </tr>
            </thead>
            <tbody data-bind="foreach: Currencies">
                <tr>
                    <td>
                        <label class="label">Date</label>
                    </td>
                    <td>
                        <input data-bind="value: CurrencyFrom, uniqueName: true" />
                    </td>
                    <td>
                        <input data-bind="value: CurrencyTo, uniqueName: true" />
                    </td>
                    <td>
                        <input data-bind="value: ConversionRate, uniqueName: true" />
                    </td>
                    <td>
                        <a href='#' data-bind='click: $root.RemoveCurrency'>Delete</a>
                    </td>
                </tr>
            </tbody>
        </table>

My JSON Return:

{"d":[{"__type":"Finance.Tracntrace.Members_Only.DAL.DataModel.Currency.CurrencyConfigurationDM","CurrencyFrom":"ZAR","CurrencyTo":"USD","Rate":null},{"__type":"Finance.Tracntrace.Members_Only.DAL.DataModel.Currency.CurrencyConfigurationDM","CurrencyFrom":"USD","CurrencyTo":"ZAR","Rate":null}]}
  • 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-17T09:34:41+00:00Added an answer on June 17, 2026 at 9:34 am

    I’ve got to admit, I’m not 100% sure what you actually are asking, but I presume that you are after an implementation of the parseExchangeRate you are using as the jsonp callback method?

    In your case, you’ll need to dive into that Yahoo return object to get the name property (query.results.row.name at a guess) and split that string to get your two currencies.

    function parseExchangeRate(yahooData)
    {
        var currencies = yahooData.query.results.row.name;
    
        // split the string to get your two currencies
        var from = whatever;
        var to = whatever;
        var rate = yahooData.query.results.row.rate;
    

    I’d then change your AddCurrency method to take a data object

        CurrencyModel.AddCurrency(from, to, rate);
    }
    
        self.AddCurrency = function (from, to, rate) {
            self.Currencies.push({
                CurrencyFrom: from,
                CurrencyTo: to,
                ConversionRate: rate
            });
        };
    

    Is that what you’re after?

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

Sidebar

Related Questions

I currently have a view, manage, that lists data items. Instead of running edit
I have an existing toolbar in my View... when I drag a Bar Button
Have a problem with updating an existing record of my DB. In my view
I have existing code that uses CMNewProfileSearch to find then iterate over the color
I have existing java code and need to create Design Document based on that.
I have existing code with their own makefiles which I want to load into
I have a form that is being used to edit existing object as well
I have a partial view that has something like this <%= Html.DropDownListFor(m => m.SelectedProductName,
I have some nested view models that implement INotifyPropertyChanged . I'd like to bind
I have a model that contains a collection, such as this: class MyModel {

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.