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

The Archive Base Latest Questions

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

Okay, I have an issue using Knockout in that it isn’t able to parse

  • 0

Okay, I have an issue using Knockout in that it isn’t able to parse a click binding on a child element of an observable array. I suspect that I’m having an issue with my mapping, but I can’t figure it out. I have a jsFiddle that I created:

http://jsfiddle.net/internetH3ro/ShjeE/1/

Here’s my JS:

var PaycheckBudgetItem = function(data) {
    var self = this;
    self.PaycheckBudgetItemId = ko.observable(data.PaycheckBudgetItemId);
    self.PaycheckBudgetId = ko.observable(data.PaycheckBudgetId);
    self.Description = ko.observable(data.Description);
    self.Amount = ko.observable(data.Amount);
    self.DueDate = ko.observable(data.DueDate);
    self.IsPaid = ko.observable(data.IsPaid);
    self.PaidStatus = ko.observable(data.PaidStatus);

    self.updateStatus = function() {
        alert('test');
    };
};

var mapping = {
    'Items': {
        create: function(options) {
            return new PaycheckBudgetItem(options.data);
        }
    }
};

var PaycheckBudget = function(data) {
    var self = this;
    self.PaycheckBudgetId = ko.observable(data.PaycheckBudgetId);
    self.PaycheckBudgetDate = ko.observable(data.PaycheckBudgetDate);
    self.PaycheckBudgetAmount = ko.observable(data.PaycheckBudgetAmount);
    self.Remaining = ko.observable(data.Remaining);
    self.Items = ko.observableArray(data.Items);
    ko.mapping.fromJSON(data.Items, mapping, self.Items);
};

var BudgetListViewModel = function(data) {
    var self = this;
    self.budgets = ko.observableArray(data);
};

var data = [
    {
    "PaycheckBudgetId": 1,
    "PaycheckBudgetDate": "11/9/2012",
    "PaycheckBudgetAmount": 2315,
    "Items": [
        {
        "PaycheckBudgetItemId": 11,
        "PaycheckBudgetId": 1,
        "Description": "Rent",
        "Amount": 400,
        "DueDate": "11/9/2012",
        "IsPaid": "Unpaid",
        "PaidStatus": false},
    {
        "PaycheckBudgetItemId": 12,
        "PaycheckBudgetId": 1,
        "Description": "Cell Phone",
        "Amount": 166,
        "DueDate": "11/9/2012",
        "IsPaid": "Unpaid",
        "PaidStatus": false}
    ],
    "Remaining": 1749},
{
    "PaycheckBudgetId": 2,
    "PaycheckBudgetDate": "11/23/2012",
    "PaycheckBudgetAmount": 2315,
    "Items": [
        {
        "PaycheckBudgetItemId": 3,
        "PaycheckBudgetId": 2,
        "Description": "Rent",
        "Amount": 400,
        "DueDate": "11/23/2012",
        "IsPaid": "Unpaid",
        "PaidStatus": false},
    {
        "PaycheckBudgetItemId": 4,
        "PaycheckBudgetId": 2,
        "Description": "Tuition",
        "Amount": 250,
        "DueDate": "11/23/2012",
        "IsPaid": "Unpaid",
        "PaidStatus": false}
    ],
    "Remaining": 1665}
];

ko.applyBindings(new BudgetListViewModel(data), $('#budget-list-container')[0]);​

Here’s my HTML:

<div id="budget-list-container" class="well sidebar-nav">
        <ul class="nav nav-list" data-bind="template: { name: 'budgetTemplate', foreach: budgets, as: 'budget' }">
            <script type="text/html" id="budgetTemplate">
                <li class="nav-header">
                    Paycheck for <span data-bind="text: PaycheckBudgetDate"></span> - <span data-bind="text: formatCurrency(PaycheckBudgetAmount)"></span>
                </li>
                <li>
                    <table class="table table-bordered table-condensed">
                        <thead>
                            <tr>
                                <th>Description</th>
                                <th>Amount</th>
                                <th>Due Date</th>
                                <th>Paid/Unpaid</th>
                            </tr>
                        </thead>
                        <tbody data-bind="template: { name: 'budgetItemTemplate', foreach: Items, as: 'budgetItem' }"></tbody>
                    </table>
                        Remaining: <span data-bind="text: formatCurrency(Remaining)"></span>
                    <hr />
                </li>
            </script>
            <script type="text/html" id="budgetItemTemplate">
                <tr>
                    <td><span data-bind="text: Description"></span></td>
                    <td><span data-bind="text: formatCurrency(Amount)"></span></td>
                    <td><span data-bind="text: DueDate"></span></td>
                    <td>
                        <button class="btn-link pull-right update-status" data-bind="text: IsPaid, click: updateStatus" />
                    </td>
                </tr>
            </script>
        </ul>
    </div>​

The meat of it is this. I have 2 KO models, PaycheckBudget and PaycheckBudgetItem. PaycheckBudget contains an observable array of PaycheckBudgetItem models. There is a function on the PaycheckBudgetItem model named “updateStatus” that is bound to a click event in my HTML. When I load my page, I get the error “Unable to parse bindings. updateStatus is not defined”.

I’m assuming that my issue is somewhere in my mapping of items. If I remove the click handler, everything binds and displays properly.

If anyone could help me out, maybe point out what I’m missing, that would be super helpful. I’m somewhat new to the Knockout stuff, so it’s likely I’m missing something obvious/simple.

(And no, none of the data in my fiddle is sensitive or real-world, just dummy data. 🙂 )

  • 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-14T17:16:31+00:00Added an answer on June 14, 2026 at 5:16 pm

    I did answer your question in the KnockoutJs JabbR chat room.

    You’re correct in your assumption. The problem seems to be mainly your mapping. You’re never even calling the constructor of the PaycheckBudget class. For example, your BudgetListViewModel constructor looks like:

    var BudgetListViewModel = function(data) {
        var self = this;
        self.budgets = ko.observableArray(data);
    };
    

    But should probably be something like:

    var BudgetListViewModel = function(data) {
        var self = this;
        self.budgets = ko.observableArray(ko.utils.arrayMap(data, function(item){
            return new PaycheckBudget(item);
        }));
    };
    

    II’ve edited your jsfiddle a little and have a working sample at: http://jsfiddle.net/KBpET/. I did edit the other mapping first, so I never checked if the item mapping is correct or not, but I’m sure you’ll be able to solve that step (the code for items has been changed in the fiddle linked).

    Hope it helps!

    /Robert

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

Sidebar

Related Questions

Okay, of course it is possible, that's no issue. In my code I have
Okay, so I have a question about using columns in a case statement that
Okay so I have encountered a frustrating issue with namespaces. I am currently using
Okay, so my issue is that i have alot of programs that i am
Okay so here my issue, I have a list of items that when a
Okay I have a large CRUD app that uses tabs with Forms embedded in
Okay, so I have this class that basically acts as a manager of an
**Okay, It's become clear that this issue is an issue related with the setup
I have a function which loads up relevant js functions on click using ajax's
Okay so I have a little issue here. I have the following class annotated

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.