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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:20:37+00:00 2026-06-04T08:20:37+00:00

I am new to knockout.js and I am missing something simple here I am

  • 0

I am new to knockout.js and I am missing something simple here I am sure. I have a list of objects in a list and I simply want to select one of them and get a property from it to load some more data.

JS:

 function category(data) {
                this.categoryName = ko.observable(data.CategoryName);
                this.categoryID = ko.observable(data.CategoryID);
            }

            function CatalogViewModel() {

                //Data
                var self = this;
                self.categories = ko.observableArray([]);
                self.chosenCategoryID = ko.observable();

                //Behaviours
                self.gotoCategory= function (category) {
                    self.chosenCategoryID(category.categoryID);
                    alert(category.categoryID);
                };

                $.getJSON("/api/catalog", function (allData) {
                    var mapped = $.map(allData, function (item) { return new category(item) });
                    self.categories(mapped);
                });
            }

            ko.applyBindings(new CatalogViewModel());

Here is my HTML:

 <ul data-bind="foreach: categories">
            <li>
                <a  data-bind="click: $parent.gotoCategory"><label data-bind="text: $data.categoryName"></label></a>
            </li>
        </ul>

The items list perfectly but then when I click and item, I am hoping to get my categoryID but I get a bunch of javascript instead which looks like a function trying to evaluate and argument.

What am I missing here?

EDIT – HERE IS WHAT I GET IN MY ALERT:

function c(){if(0<arguments.length){if(!c.equalityComparer||!c.equalityComparer(d,arguments[0]))c.I(),d=arguments[0],c.H();return this}a.U.La(c);return d}function c(){if(0<arguments.length){if(!c.equalityComparer||!c.equalityComparer(d,arguments[0]))c.I(),d=arguments[0],c.H();return this}a.U.La(c);return d}
  • 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-04T08:20:38+00:00Added an answer on June 4, 2026 at 8:20 am

    It appears that your categoryID is an observable. To access the value of an observable, you need to call it as a function with no arguments.

    So, your gotoCategory should look more like:

                self.gotoCategory= function (category) {
                    self.chosenCategoryID(category.categoryID());
                    alert(category.categoryID());
                };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to WPF so I'm sure it's an easy one this; for every control
All the knockout examples I have found seem to add a new item to
I have a view model something like below, when onAfterRender is fired by Knockout
I am new to Knockout Js..I have this issue on my page that when
New to javascript, but I'm sure this is easy. Unfortunately, most of the google
New to FluentNHibernate =D I have a parent/children classes as follows: public class Parent
New to Quartz and I am curious on the drawing speeds of simple shapes,
I'm new to knockout js and got an observable array, when populating the array
A knockout datepicker data binder can be found here: jQuery UI datepicker change event
I have company list, when clicking on each company need to show the salespersons

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.