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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:16:21+00:00 2026-06-14T08:16:21+00:00

I use knockoutjs.mapping to map an existing object return be the server is JSON.

  • 0

I use knockoutjs.mapping to map an existing object return be the server is JSON.

The object is similar to the cart editor example, the main difference in the items already exists.

Here is my attempt http://jsfiddle.net/9ej3r/

mapping is straight-forward:

var mapping = {
            'Items': {
                create: function(options) {
                    return new InvoiceItem(options.data);
                },
                key: function(data){
                    return ko.utils.unwrapObservable(data.ID);
                }
            }
        };

when i click remove, i get the error: “this.Items in undefined”

what am i doing wrong here? how can adapt the cart editor example to work with existing lines ?

  • 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-14T08:16:22+00:00Added an answer on June 14, 2026 at 8:16 am

    You have been bitten by the fact how this works in javascript.

    Because when your removeItem method gets called the this will be the actual item e.g. an InvoiceItem not the Invoice so you need to capture the “other” this in a variable and use that in your function to access the Invoice.

    So your removeItem should look like this:

    var self = this;
    
    this.removeItem = function (item) { 
       self.Items.remove(item);
    }
    

    See also this Demo.

    You should note that the cart editor example also uses this technique in the removeLine method

    var self = this;
    self.removeLine = function(line) { self.lines.remove(line) };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working through the mapping plugin example on the Knockoutjs website. This is
I have created a View Model object for use with KnockoutJS. It has a
I'm trying to use KnockoutJS to build an interactive dashboard with data bindings on
I want to use $index in KnockoutJS to show alphabets instead of numbers.e.g, A.
I recently started working with KnockoutJs and quickly realized using the default Json(myModelWithADate) resulted
is it possible to use an external Template in KnockoutJS like this? <script type=text/html
I have a jQuery template, and I would like to use a KnockOutJS template
I've written a few custom bindings using KnockoutJS. I'm still unsure when to use
I am having an issue with the knockoutjs if binding. I use the binding
I'm trying to use knockout.js to perform add/remove operations on a server-side property. Here's

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.