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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:27:20+00:00 2026-06-01T19:27:20+00:00

I am creating a list of links using a knockout binding: The Javascript and

  • 0

I am creating a list of links using a knockout binding:

The Javascript and view model looks like this:

$(function () {
   var adminViewModel = function()
   {
       var self = this;
       self.leftItems = ko.observable([ { Name: "Item1", Id: 0 }]);
       self.getChildren = function (id, list) {
           var url ="@Url.Content("~/api/Test/GetChildren/")" + id;
           $.getJSON(url, function (data) {
              list(data);
           });
        };
    }
    var Admin3App = window.Admin3App = window.Admin3App || {};

    Admin3App.viewModel = new adminViewModel();
    ko.applyBindings(Admin3App.viewModel);

    function getLeftChildren(id)
    {
        Admin3App.viewModel.getChildren(id, Admin3App.viewModel.leftItems);
    }
    getLeftChildren(0);

}

(EDIT: the init of the ko.observable was missing an Id (even though this did not cause an error, added it)

How this works is the view model will load a bunch of items that has no parent (id 0).
For the sake of simplicity I only included the left version. But the page has a list of items on the left and right so there is a function for each.

The left items is populated to view model left items and displayed as below. But each item is a link and once clicked via javascript will refresh the items based on the parent Id. (Much like browsing a folder viewer in explorer).

But i cannot figure out how to declare the binding in knockout to build up the url. I know this is probably rediculously easy and I am just missing it.

here is the html I have attempted amongst others

<div class="leftView">
    <div data-bind="foreach: leftItems">
        <a data-bind="text: Name, attr : { href:'javascript:getLeftChildren(' + Id + ')' }"></a><br />
    </div>
</div>

(EDIT: missed a single quote, but got the same error anyway)
But I keep getting a binding error

  • 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-01T19:27:21+00:00Added an answer on June 1, 2026 at 7:27 pm

    A couple of things:

    1) leftItems should ideally be an observableArray

    2) The initial object you push into leftItems does not have an Id property

    Here is a JSfiddle that corrects a few things and demonstrates loading an initial set of data and then calling again to load different data. I’ve also moved the outside JavaScript call inside the viewModel and switched to using a click handler to pass refresh the data (note that a click binding will automatically send the data item into the event handler as the first parameter, so you have access to the id you need for creating your URL).

    http://jsfiddle.net/jearles/xTHFg/

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

Sidebar

Related Questions

I'm creating a list of class Task in a way such as this. List<Task>
Why does this attempt at creating a list of curried functions not work? def
Outside of a for I declare a variable using var list; . I use
We're creating a page in Orchard CMS using the 'List' Content Type. We want
I'm creating a standard image gallery using FancyBox. The page shows a list of
I've read the links listed when I was creating this question. I think what
I have a method that loops through a list and creates Links using the
I am creating a small directory with links to scroll to the alphabetical list
Using this source code in a razor view: @for( int x = 0; x
I'm creating a list of search results, using an unordered list, each <li> is

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.