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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:39:20+00:00 2026-06-10T15:39:20+00:00

Edit Looks like I got it loading from the server now. If anyone sees

  • 0

Edit Looks like I got it loading from the server now. If anyone sees any issues with this, would love to hear about them.

Having some issues getting the knockout mapping plugin working. I can get this working with static data with no problems, see http://jsfiddle.net/RH9wQ/

When I try to load in data from the server, it doesn’t seem to work, though. Below is the bare bones code I’m using. The data in the jsfiddle is the exact data that’s being returned from my server. Am I missing something completely obvious?

What I’m doing is loading in different drugs based on alpha buttons that are clicked. So click on “y” and get a list of drugs that start with y, click on “z” and get a list of drugs that start with z. When the buttons are clicked/data is loaded, I want to replace my viewModel data with what’s coming in from the server.

Also, note the console on the jsfiddle page, data looks fine (8 array elements and count=8), but note the console of the viewModel, preferredDrugs and count are different, anyone know why this is?

$(function() {
    $('.load').click(function() {
        var $letter = $(this).attr('value');

        //show spinner
        $('#loading').show();

        //load in drug list data
        $.getJSON('/PreferredDrugList/service/preferredDrugs/' + $letter, function(data) {
            //hide spinner
            $('#loading').hide();

            console.log(data);
            //create observable properties for each of the properties on data
            ko.mapping.fromJS(data, viewModel);
            console.log(viewModel);

        });
    });

});//end ondomready

//default data
var data = {
    preferredDrugs: [],
    count: 0
};

var viewModel = ko.mapping.fromJS(data);

ko.applyBindings(viewModel);
  • 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-10T15:39:22+00:00Added an answer on June 10, 2026 at 3:39 pm

    When updating an existing view model using ko.mapping you can also try:

    ko.mapping.fromJS(data, {}, viewModel);
    

    ..instead of..

    ko.mapping.fromJS(data, viewModel);
    

    Also, note the console on the jsfiddle page, data looks fine (8 array
    elements and count=8), but note the console of the viewModel,
    preferredDrugs and count are different, anyone know why this is?

    Yes, the original preferred drugs is a normal array while the new preferred drugs is an observable array. An observable array will look like an empty array if you try to access it directly. However, observables are functions and need to be treated as such.

    So…

    console.log(myViewModel.preferredDrugs);
    

    …returns an empty array, whereas…

    console.log(myViewModel.preferredDrugs());
    

    …returns the actual array.

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

Sidebar

Related Questions

So here is what the method looks like now: POST person/personId/edit https://api.example.com/*key*/person/*personId*/edit?FName=Blah I want
i got a generic list that looks like this: List<PicInfo> pi = new List<PicInfo>();
I've got a query that looks like.. SELECT id_b FROM id_table WHERE id_a =
I've got a file (leaderboard.txt) that looks like this: funkystudios funkystudios funkystudios gilletteracer74 axehairgel
I've got a struct that looks like this: public struct MyStruct { public const
I have got a window that looks like window1 and I would like it
Second EDIT: Looks like my issue might be where the date is set from
So I've got code that looks like this: <input class=messageCheckbox type=checkbox value=3 name=mailId[]> <input
I've got some HTML that looks like this: <tr class=row-even> <td align=center>abcde</td> <td align=center><a
I've got HTML code that roughly looks like this: <li id=someid-11> <img src=... alt=alt

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.