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

The Archive Base Latest Questions

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

I wish to use Knockout mapping to generate ViewModel. var viewModel = ko.mapping.fromJS(data); After

  • 0

I wish to use Knockout mapping to generate ViewModel.

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

After creating ViewModel I would like to add computed text element.

for (var i = 0; i < viewModel.Packages().length; i++) {
    var pack = viewModel.Packages()[i];
    pack.packageClass = ko.computed(function() {
        return this.Height() * this.Depth() * this.Width()
    }, pack);
}

Bind the page.

ko.applyBindings(viewModel);

Page is working fine in this state…

But now user would like to “save” and “reload” page.
This would be done using mapping feature which updates ViewModel with new data.

data = ko.mapping.toJSON(viewModel);

But it is not possible to add again those computed fields before rebinding page. And I will get error that computed element is not found (anymore).

ko.mapping.fromJS(data, viewModel);

Am I doing something totally wrong?

Everything works fine without computed fields or without reloading ViewModel…

Update: Fiddle updated to work like in solution.

Fiddle sample

  • 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-15T02:34:18+00:00Added an answer on June 15, 2026 at 2:34 am

    Create a explicit ViewModel

    PackageViewModel = function(data) {
        ko.mapping.fromJS(data, {}, this);
    
        this.packageClass = ko.computed(function() {
            return this.Height() * this.Depth() * this.Width()
        }, this);
    };
    

    then use mappign options like this

    var mapping = {
       Packages: {
          create: function(options) {
             return new PackageViewModel(options.data);
          }
       }
    };
    
    ko.applyBindings(ko.mapping.fromJS(data, mapping));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish to use Google custom search and in particular would like to have
I wish to use forms to input data to an e-commerce cart I use,
When creating a form, I wish to use one field on the model as
I am creating a set of controls that I wish to use in both
I wish to use the paperclip gem to add an image that I am
I wish to use scribe to export some data from a Erlang application, but
I wish to use this method like @results = Candidate.all.match_against(options) , where options is
I wish to use xml and xsl to generate controls on an asp.net page.
We wish to use jquery/javascript to add 'alternate link rss' elements in the section
I wish to use a command-line application, like cURL , to do some test

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.